我正在尝试从python2x执行一个程序。
在终端中,作业将以下列方式运行:
mpirun -np 8 ~/WORK/scf Fe_SCF.inp > Fe_SCF.out其中Fe_SCF.*是CWD中的输入和输出。
现在,我试图从python脚本中运行这段代码。此后,我将它们定义为变量,并试图将其调用为:
call(["mpirun -np 8 ~/WORK/scf", scfin, scfout])给予错误:
File "./triolith.py", line 38, in <module>
call(["mpirun -np 8 ~/WORK/scf", scfin, scfout])
File "/usr/lib64/python2.7/subprocess.py", line 522, in call
return Popen(*popenargs, **kwargs).wait()
File "/usr/lib64/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/usr/lib64/python2.7/subprocess.py", line 1335, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory使用真正的文件名也不能解决这个问题:
call(["mpirun -np 8 ~/WORK/scf", "Fe_SCF.inp", "Fe_SCF.out"])这会产生错误:
File "./triolith.py", line 38, in <module>
call(["mpirun -np 8 ~/WORK/scf", "Fe_SCF.inp", "Fe_SCF.out"])
File "/usr/lib64/python2.7/subprocess.py", line 522, in call
return Popen(*popenargs, **kwargs).wait()
File "/usr/lib64/python2.7/subprocess.py", line 710, in __init__
errread, errwrite)
File "/usr/lib64/python2.7/subprocess.py", line 1335, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory我已经检查并可以确认,使用os.system使用的是"Real“文件名,但不使用变量名,如:
os.system("mpirun -np 8 ~/WORK/scf scfin" )因此,使用两种方法中的任何一种,我如何用变量名调用程序作为输入和输出?
发布于 2015-09-25 09:06:22
call获取一个列表,因此您的第一个示例应该是:
cmd = ['/absolute/path/to/mpirun', '-np', '8', '~WORK/scf', var_1]
call(cmd, stdout=var_2, stderr=STDOUT)发布于 2015-09-25 09:02:02
在使用OS模块的后一个示例中,您应该能够:
os.system("mpirun -np 8 ~/WORK/scf "+ var_name)来运行您的函数调用。
对于多个变量,d:
os.system("mpirun -np 8 ~WORK/scf " + var_1 + " " + var_2)https://stackoverflow.com/questions/32778441
复制相似问题