带有复杂命令的Python子进程
这个问题源于我对UNIX命令和子流程模块的结构缺乏了解,因此请原谅我的幼稚 我有一个命令,看起来像这样带有复杂命令的Python子进程,python,python-2.7,subprocess,mpi,os.system,Python,Python 2.7,Subprocess,Mpi,Os.system,这个问题源于我对UNIX命令和子流程模块的结构缺乏了解,因此请原谅我的幼稚 我有一个命令,看起来像这样 path/to/openmpi/mpirun -machinefile machine.file -np 256 /path/to/excecutable </dev/null &> output.out & path/to/openmpi/mpirun-machinefile machine.file-np 256/path/to/excecutable out
path/to/openmpi/mpirun -machinefile machine.file -np 256 /path/to/excecutable </dev/null &> output.out &
path/to/openmpi/mpirun-machinefile machine.file-np 256/path/to/excecutable output.out&
我知道MPIrun的结构是如何工作的,我认为我的可执行文件将其数据写入stdout,然后我将其重定向到一个名为output.out的文件。我已经在使用os.sys()的python脚本中使用了这个命令,但是我想使用subprocess,这样当可执行文件(在后台)完成运行时,python脚本就可以继续执行“任务”
我不知道从哪里开始,因此如果有人有任何提示或可以告诉我如何正确格式化子流程命令,我将非常感激。所有个人尝试使用子流程都会导致epic失败
谢谢 这很简单
from subprocess import call
call(["path/to/openmpi/mpirun", "-machinefile machine.file -np 256 /path/to/excecutable </dev/null &> output.out &"])
来自子流程导入调用
调用([“path/to/openmpi/mpirun”,“-machinefile machine.file-np 256/path/to/excecutable output.out&]”)
通常,您会将参数作为列表提供给命令,但我认为这也应该可以。如果不是,则将每个参数分解为列表中的新元素
答案更深入地说明了这种方法的局限性。我认为这是可行的,但如何让子流程等待可执行文件完成其任务,然后再进行其他操作呢?在这种情况下,子流程不会认为它一发出命令就完成了吗?在Python文档中:
subprocess.call(args,*,stdin=None,stdout=None,stderr=None,shell=False)
“运行args描述的命令。等待命令完成,然后返回returncode属性。”。