简体   繁体   中英

Executing command line command from Python

I know people have addressed things similar to this, but I am still confused.

I want to execute a command "Inventory.bat rap.t00z.awp236pgrbf00.grib2 rap.t00z.awp236pgrbf00 LoLa 25 48 33 -122 -83" in windows command line using Python.

My current Python script is:

import subprocess
subprocess.check_output(['Inventory.bat', 'rap.t00z.awp236pgrbf00.grib2 rap.t00z.awp236pgrbf00', 'LoLa', '25', '48', '33', '-122', '-83'])

This doesn't work when executed by Python. What am I missing?

Thanks for your help!

Under Windows, .bat files are executed by the cmd shell. To use the shell you must include the shell=True option to the subprocess functions.

subprocess.check_output(['Inventory.bat', 'rap.t00z.awp236pgrbf00.grib2 rap.t00z.awp236pgrbf00', 'LoLa', '25', '48', '33', '-122', '-83'], shell=True)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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