简体   繁体   中英

How to run perl script with multiple args from python script

I made a python code that must sequentially execute a series of perl commands on the PC shell, the problem is that I did not realize that to send these scripts I have to add parameters (i have n_params), advice?

example command to send perl [file_name.pl] [params]

To run these commands on the windows CMD I am using os and subprocess

python code example

# command = perl [file_name.pl] [params]
# path = location/of/where/the/pl/file/is/saved

perl_script = subprocess.Popen(["C:\\Perl64\\bin\\perl.exe",path + command], stdout=sys.stdout)
perl_script.communicate()

But running the script like this, the code gets me wrong because it says it can't find the filename in the specific directory

This argument to Popen()

["C:\\Perl64\\bin\\perl.exe", path + command] 

does not look correct since you wrote that command is perl [file_name.pl] [params] . Instead try:

p = subprocess.Popen(["C:\\Perl64\\bin\\perl.exe", path+"file_name.pl", "param1", "param2", ...])

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