我正在尝试在python脚本中运行命令,如下所示:
subprocess.call("ghdl -a --ieee=synopsys -fexplicit " + testBenchFile + " >> a_log.txt", shell = True)
“testBenchFile是一个字符串,但它会抛出”找不到命令“错误。
我做错了什么?
答案 0 :(得分:1)
变化:
subprocess.call("ghdl -a --ieee=synopsys -fexplicit " + testBenchFile + " >> a_log.txt", shell = True)
为:
subprocess.call(["ghdl", "-a", "--ieee=synopsys", "-fexplicit", testBenchFile, ">>", "a_log.txt"], shell = True)
您还可以更加“pythonic”并与您的日志文件配合使用:
log_file = open("a_log.txt", "a")
subprocess.call(["ghdl", "-a", "--ieee=synopsys", "-fexplicit", testBenchFile], shell = True, stdout=log_file)
使用stdout
参数,您将重定向命令的输出,例如>
。但是,由于文件是使用模式"a"
打开的,因此您可以模拟>>
。
答案 1 :(得分:0)
尝试将args作为列表提供。
subprocess.call(["ghdl", "-a", "--ieee=synopsys", "-fexplicit", testBenchFile, ">>", "a_log.txt"], shell = True)