我想从python运行脚本,其运行方式为:./cj 3 0.01 2 < matrix.txt
。当我在代码中使用以下代码时:os.system('./cj 80 0.01 2 < temp')
。它返回状态码512。temp是c程序的输入,就像matrix.txt
答案 0 :(得分:0)
您应该尝试使用子流程模块:
import subprocess
process = subprocess.Popen(["./cj", "80", "0.01", "2", "<", "temp"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
stdout, stderr = process.communicate()
if process.returncode:
print("Return code: %s STDERR: %s" % (process.returncode, stderr))