简体   繁体   English

从python启动cmd.exe并使用多个参数调用bat文件

[英]start cmd.exe from python and call a bat file with multiple parameters

I'd like to load cmd.exe and call a bat file with multiple parameters. 我想加载cmd.exe并使用多个参数调用bat文件。 All these from python. 所有这些都来自python。

My bat file looks like: 我的蝙蝠文件看起来像:

  @echo off
  call ifortvars.bat intel64
  cd %5
  abaqus job=#1 user=%2 cpus=%3 gpus=%4 interactive

My python code: 我的python代码:

os.system("start cmd.exe /k C:/Users/username/desktop/file.bat" params)

where: 哪里:

params = [JobName, fname, str(numcpus), '1', 'C:/Abaqus_Jobs' + JobDir]

JobName = 'A2'
JobDir = 'Job1/input_files'
fnameUEL = 'routineUEL'
numcpus = 8

Now this code does not work because params is a list. 现在,此代码不起作用,因为params是一个列表。 If I change it to: 如果我将其更改为:

os.system("start cmd.exe /k C:/Users/username/desktop/file.bat JobName  fname  str(numcpus)  '1'  'C:/Abaqus_Jobs' + JobDir)

it also does not work. 它也不起作用。 I've read that cmd in windows works: 我读过Windows中的cmd可以用:

Spaces in Program Path + parameters with spaces:
CMD /k ""c:\batch files\demo.cmd" "Parameter 1 with space" "Parameter2 with space""

but if I try: 但是如果我尝试:

os.system("start cmd.exe /k ""C:/Users/username/desktop/file.bat" "JobName"  "fname" "str(numcpus)"  "1"  "'C:/Abaqus_Jobs' + JobDir"")

it doesn't work either. 它也不起作用。 Any ideas? 有任何想法吗? Thanks! 谢谢!

Solved it with: 解决了:

process = Popen(params , stdout=PIPE, stderr=PIPE, shell=True)

params = [['cmd', '/k', 'start', ....]]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM