我正在尝试编译一组行并执行它们并将输出 append 到文本文件。我没有写同样的东西,而是使用 python 脚本在后台编译和执行。
import subprocess
subprocess.call(["ifort","-openmp","mod1.f90","mod2.f90","pgm.f90","-o","op.o"])
subprocess.call(["nohup","./op.o",">","myout.txt","&"])
程序 pgm.f90
正在使用 ifort 编译器编译,但输出没有 append 到 myout.txt
。相反,它将输出 append 到 nohup.out
,即使在 python 脚本中指定了 "&"
之后,程序也不在后台运行。
我在这里犯了什么明显的错误?
提前致谢
最佳答案
您可以通过使用带有参数 shell=True
的 Popen()
来像在 shell 中一样调用子进程:
subprocess.Popen("nohup ./op.o > myout.txt &", shell=True)
关于python - 从python执行shell命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18390630/