Lorenzo__
Lorenzo__

Reputation: 35

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

Upvotes: 0

Views: 324

Answers (1)

Håkon Hægland
Håkon Hægland

Reputation: 40778

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", ...])

Upvotes: 2

Related Questions