我有这个代码调用一个bat文件与popen:
jobname = A2
fname = routineUEL
def issue_command(*args):
import subprocess
process = subprocess.popen(args, stdout=subprocess.pipe, stderr = subprocess.pipe, shell = true)
args = [['c:usersdesktop\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窗口打开。我想cmd窗口也与python打开。什么好主意吗?由于
如果想要命令窗口出现,那么您可以通过cmd.exe
执行它。
cmd.exe /K 'c:\users\desktop\rel.bat'
.
/K
指示cmd.exe
执行批处理文件并保持打开状态
@jpcgandre在辅助bat文件中,是否只包含一行代码?或者还有更多?你想把这行附加到rel。bat吗?你能说得更具体一点吗?这里有一个解决方案:
with open("rel.bat","a") as text_file:
print("cmd.exe /K 'c:\users\desktop\rel.bat'", file=text_file)