我有这个用popen调用bat文件的代码:
jobname = A2
fname = routineUEL
def issue_command(*args):
import subprocess
process = subprocess.popen(args, stdout=subprocess.pipe, stderr = subprocess.pipe, shell = true)
args = [['c:\users\desktop\\rel.bat', jobname, fname, '8', '1', ' c:\abaqus_jobs']]
for arg in args:
out, err = issue_command(*arg)
bat文件是:
@echo off
call ifortvars.bat intel64
cd %5
abaqus job=#1 user=%2 cpus=%3 gpus=%4 interactive
问题是:当我运行python脚本时,bat命令在后台运行,没有cmd窗口打开。当我手动运行bat文件时,将打开cmd窗口。我想用cmthon打开cmd窗口。有任何想法吗?谢谢
答案 0 :(得分:1)
如果要显示命令窗口,则可以通过cmd.exe
执行该命令窗口。
cmd.exe /K 'c:\\users\\desktop\\rel.bat'
。
/K
指示cmd.exe
执行批处理文件并保持打开状态。
答案 1 :(得分:0)
with open("rel.bat","a") as text_file:
print("cmd.exe /K 'c:\\users\\desktop\\rel.bat'", file=text_file)