jjzjj

python - 用 Python 子进程替换 popen2

我尝试从“FredLunde”的“PythonStandardLibrary”一书中运行这段代码。importpopen2,stringfin,fout=popen2.popen2("sort")fout.write("foo\n")fout.write("bar\n")fout.close()printfin.readline(),printfin.readline(),fin.close()它运行良好,但有一个警告~/python_standard_library_oreilly_lunde/scripts/popen2-example-1.py:1:DeprecationWarn

Python 子进程交互,为什么我的进程使用 Popen.communicate 而不是 Popen.stdout.read()?

我正在尝试使用subprocess模块与使用Python的命令行聊天机器人进行通信。(http://howie.sourceforge.net/使用编译后的win32二进制文件,我有我的理由!)这个有效:proc=Popen('Howie/howie.exe',stdout=PIPE,stderr=STDOUT,stdin=PIPE)output=proc.communicate()但是Popen.communicate等待进程终止(并向其发送EOF?),我希望能够与其进行交互。明显的解决方案是像这样读取stdout/写入stdin:这行不通:proc=Popen('Howie/how

python - "The system cannot find the file specified"在 python 中调用 subprocess.Popen 时

我正在尝试使用svnmerge.py来合并一些文件。在引擎盖下它使用python,当我使用它时出现错误-“系统找不到指定的文件”。工作中的同事正在运行相同版本的svnmerge.py和python(2.5.2,特别是r252:60911),没有任何问题。我找到了thislink,它描述了我的问题。尝试那里概述的内容,我确认Python可以找到SVN(它在我的路径中):P:\>pythonPython2.5.2(r252:60911,Feb212008,13:11:45)[MSCv.131032bit(Intel)]onwin32Type"help","copyright","credi

python - 为什么 subprocess.Popen(...) 不总是返回?

我希望这是一个简单的python问题。当我在python解释器中尝试以下操作时:>>>importprocess>>>deftest(cmd):...p=subprocess.Popen(cmd)...>>>test(['ls','-l'])它将运行ls-l,但我需要点击“返回”以获得新的>>>提示符。但是,当我尝试以下操作时:>>>importprocess>>>deftest(cmd):...p=subprocess.Popen(cmd)...p.wait()...>>>test(['ls','-l'])然后ls-l将运行并立即出现>>>提示符。另一个变体:>>>importpro

python - 子进程 popen.communicate() 与 stdin.write() 和 stdout.read()

我注意到两种不同的行为和两种方法应该会产生相同的结果。目标-使用subprocess模块执行外部程序,发送一些数据并读取结果。外部程序为PLINK,平台为WindowsXP,Python3.3版本。主要思想-execution=["C:\\Pr..\\...\\plink.exe","-l",username,"-pw","***",IP]a=subprocess.Popen(execution,bufsize=0,stdout=PIPE,stdin=PIPE,stderr=STDOUT,shell=False)con=a.stdout.readline()if(con.decode(

python - Popen.poll() 和 Popen.wait() 的区别

我正在使用以下命令来运行shell命令(创建子进程):cmd="ls"process=subprocess.Popen(cmd,shell=True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT,universal_newlines=True)然后,我想在它完成时得到它的返回码。我应该使用wait()还是poll()?在我看来,wait()等于包含在繁忙等待中的poll()。像这样的东西:whileprocess.poll()==None:time.sleep(0.5)我读到如果stdout/stderr缓冲区已满,wait()可能会产

python - 调试 subprocess.Popen 调用

我一直在使用subprocess.Popen过去成功地,当用python脚本包装二进制文件以格式化参数/自定义等...开发第n个包装器,我像往常一样......但没有任何反应。这是小代码:printcommandp=subprocess.Popen(command,shell=True)result=p.communicate()[0]printvars(p)returnresult这是输出:/usr/bin/sh/tmp/run/launch.sh{'_child_created':True,'returncode':0,'stdout':None,'stdin':None,'pid

python - Pylint 误报 E1101 : Instance of 'Popen' has no 'poll' member

Pylint为子进程模块返回大量误报:E1101:184,7:resetboard:Instanceof'Popen'hasno'poll'memberE1101:188,4:resetboard:Instanceof'Popen'hasno'terminate'member#etc.我该如何解决这个问题? 最佳答案 此错误已在logilab-astng包中确定:http://www.logilab.org/ticket/46273他们创建了一个名为pylint-brain的新副项目,它将是一组插件并包含在logilab-astng

python subprocess.Popen挂起

child=subprocess.Popen(command,shell=True,env=environment,close_fds=True,stdout=subprocess.PIPE,stderr=subprocess.STDOUT,bufsize=1,)subout=""withchild.stdout:forlineiniter(child.stdout.readline,b''):subout+=linelogging.info(subout)rc=child.wait()有时(间歇性地)这会永远挂起。不确定它是否卡在iter(child.stdout.readline)

使用 subprocess.Popen 的 Python 内存分配错误

我正在做一些生物信息学工作。我有一个python脚本,它有时会调用一个程序来执行一个昂贵的过程(序列对齐……使用大量的计算能力和内存)。我使用subprocess.Popen调用它。当我在测试用例上运行它时,它完成并完成得很好。但是,当我在完整文件上运行它时,它必须对不同的输入集执行多次,它就死了。子进程抛出:OSError:[Errno12]Cannotallocatememory我找到了几个链接here和here和here类似的问题,但我不确定它们是否适用于我的情况。默认情况下,序列比对器会尝试申请51000M的内存。它并不总是使用那么多,但它可能会。加载和处理完整的输入后,就没有