【python-process.communicate和getche()失败】教程文章相关的互联网学习教程文章

Python在使用multiprocessing.pool.map()调用的函数中递增一个数字【代码】

我试图在multiprocessing.pool.map()调用的函数中按顺序递增一个数字.当我运行以下代码时,我得到的数字增加的次数与每个数字的池数相同.import time import multiprocessing import decimal import randomlists = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h','i', 'j', 'k'] def thefunction(listi):global numbernumber += 1time.sleep(decimal.Decimal(random.random()))print time.strftime('%H:%M:%S'), number, listinumber = 0...

python – 何时使用subprocess.call()或subprocess.Popen(),运行airodump【代码】

我有这个小脚本,可以让您的无线设备进入监控模式.它执行airodump扫描,然后在终止扫描后将输出转储到file.txt或变量,这样我就可以刮掉BSSID以及我可能需要的任何其他信息. 我觉得我没有理解subprocess.call()和subprocess.Popen()之间的概念或区别. 这就是我目前拥有的:def setup_device(): try:output = open("file.txt", "w")put_device_down = subprocess.call(["ifconfig", "wlan0", "down"])put_device_mon = subprocess.call...

python – 使用grep:exit-status 2的Subprocess.check_output【代码】

我之前使用过的子进程没有任何问题,出于某种原因,当我用grep尝试它时:grepOut = subprocess.check_output("grep 'hello' tmp", shell=True)我收到以下错误:File "/usr/lib/python2.7/subprocess.py", line 544, in check_outputraise CalledProcessError(retcode, cmd, output=output) subprocess.CalledProcessError: Command '['grep', "'hello'", 'tmp']' returned non-zero exit status 2直接在终端中输入命令,我没有收到任何...

python – 为什么我们必须在subprocess.Popen中使用列表?【代码】

我的问题更具理论性而非实际性,我找到了更多的答案,解释了我们为什么要在subprocess.Popen调用中使用列表. 例如,众所周知:Python 2.7.10 (default, Oct 14 2015, 16:09:02) [GCC 5.2.1 20151010] on linux2 Type "help", "copyright", "credits" or "license" for more information. >>> import subprocess >>> cmd = subprocess.Popen(["python", "-V"], stdout=subprocess.PIPE) Python 2.7.10然后我在UNIX中乱搞并找到了一些有...

text-processing – 编写用于编辑.txt数据的程序 – Python还是Unix?【代码】

我只有很少的编程经验,而且我正在努力提高自己的技能.基本上,我需要编写一个程序,它可以对.txt文件中的某些数据执行某些特定的处理. 从头开始,我有一个.txt文件,其数据如下所示:>tex_1 abcdefghijklmnopqrstu >tex_2 abcdefghijklmnopqrstuv >tex_3 abcdefghijklmnopqrstuv >tex_4 abcdefghijklmnopqrst // x >tex_1 abcdefghijklmnopqrstu >tex_2 abcdefghijklmnopqrstuv >tex_3 abcdefghijklmnopqrst >tex_4 abcdefghijklmn...

使用shebang使用subprocess.call执行python脚本【代码】

我正在用Python 3编写一个(某种程度上)模块化的应用程序,我想从它运行任意程序,表示程序是在运行时指定的,而不一定是python脚本. 所以我用例如,subprocess.call([spam, "-i", eggs, "-o", ham])如果垃圾邮件是一个python脚本,shebang到python3和可执行权限,我得到OSError: [Errno 8] Exec format error如果我subprocess.call(["python3", spam, "-i", eggs, "-o", ham])它工作正常. 你知道为什么吗?如何在不指定python3的情况下运...

Python:kernel32.CreateProcessA()它在做什么?【代码】

我目前正在学习调试器以及它们如何停止进程. 这是我的代码:from ctypes import *WORD = c_ushortDWORD = c_ulongLPBYTE = POINTER(c_ubyte)LPTSTR = POINTER(c_char)HANDLE = c_void_pDEBUG_PROCESS = 0x00000001CREATE_NEW_CONSOLE = 0x00000010class STARTUPINFO(Structure):_fields_ = [("cb", DWORD),("lpReserved", LPTSTR),("lpDesktop", LPTSTR),("lpTitle", LPTSTR),("dwX", DWORD),("dwY", DWORD),("dwXSize", DWORD),("...

python – Threads中的subprocess.Popen【代码】

我有很多文件(超过4000个),我想同时加载到PostgreSQL中.我已将它们分成4个不同的文件列表,我想要一个线程迭代加载数据的每个列表. 我遇到的问题是我使用os.system来调用加载程序但这会阻止其他线程同时运行.如果我使用subprocess.Popen然后它们同时运行但是线程认为它们已经完成了execeuting,所以移动到我的脚本的下一部分. 我这样做是对的吗?或者是否有更好的方法从线程内调用子进程.def thread1Load(self, thread1fileList):con...

Python:subprocess32 process.stdout.readline()等待时间【代码】

如果我使用例如“ls -Rlah /”运行以下函数“run”,我会立即通过print语句获得输出import subprocess32 as subprocess def run(command):process = subprocess.Popen(command,stdout=subprocess.PIPE,stderr=subprocess.STDOUT)try:while process.poll() == None:print process.stdout.readline()finally:# Handle the scenario if the parent# process has terminated before this subprocessif process.poll():process.kill()但是...

什么是Python的subprocess.Popen()的Java等价物?【代码】

import subprocess import osprefix = os.path.expanduser("~/.bin/kb/") p = subprocess.Popen([(prefix + "koreball"),(prefix + "/data"),'3'])解决方法:您可以尝试使用Runtime.exec方法.Runtime runtime = Runtime.getRuntime(); Process process = runtime.exec("myprocess");该方法返回一个可用于: >检索过程输出,输入和错误流>检索流程输出代码>杀死这个过程>等待流程执行结束

Python multiprocessing、pool

multiprocessing 由于Windows没有fork调用,multiprocessing模块提供了一个Process类来提供实现多进程的方式;import os from multiprocessing import Processx1, x2 = 3, 7def run_add(x1, x2):print("this is child process, the pid is %s" % os.getpid())print('x1 + x2 =', x1+x2)print("******the end*******")if __name__ == '__main__':print("this is parent process, the pid is %s" % os.getpid())print('x1 * x2 =', x...

python – 为什么subprocess.call忽略“*”星号传递’mv’命令[复制]【代码】

参见英文答案 > Python subprocess Popen: Why does “ls *.txt” not work? 2个我试图将tmp目录移动到目标路径时遇到问题tmp = tempfile.mkdtemp()创建tmp目录 在tmp目录中生成几个子目录和文件subprocess.call(['mv',tmp+'/*','destinationDir']) 将生成的子目录移动到目标文件夹. 但是subprocess.call它将tmp目录移动到目的地,而我想只移动tmp的所有子目录而不是tmp本身. 我尝试在终端中的...

python – os.fork和multiprocessing.Process之间的行为差​​异【代码】

我有这个代码:import ospid = os.fork()if pid == 0:os.environ['HOME'] = "rep1"external_function() else:os.environ['HOME'] = "rep2"external_function()而这段代码:from multiprocessing import Process, Pipedef f(conn):os.environ['HOME'] = "rep1"external_function()conn.send(some_data)conn.close()if __name__ == '__main__':os.environ['HOME'] = "rep2"external_function()parent_conn, child_conn = Pipe()p = P...

python – Subprocess.Call失败“系统无法找到指定的文件”【代码】

我一直在研究这个问题一小时,这令人愤怒: 我有一个名为Manipula的.exe文件,它的源代码是.msu文件.我可以通过命令行成功运行我想要的东西,如下所示:"C:/Flow Check/Run Quick/Applications/Manipula.exe" "C:/Flow Check/Data Processing/BLAISE TO BLAISE.msu"但是,我无法在Python中模拟这种行为 – 无论我使用什么.我试过了os.system和subprocess.call和subprocess.Popen 如果我运行如下的东西p= subprocess.Popen("C:/Flow Che...

使用subprocess.Popen从python调用pandoc【代码】

我在使用subprocess.Popen从python调用pandoc时遇到问题.这一切都在控制台中工作.这是代码.# Test markdown file here is just a simple markdown file.现在我使用该文件名的python代码是我的markdown文件的完整路径:import subprocess fileout = os.path.splitext(filename)[0] + ".pdf" args = ['pandoc', filename, '-o', fileout] subprocess.Popen(args)我也尝试了各种方法来捕获错误,但这不起作用.但是,在控制台中,一切正常...