Reputation: 31
Need help with integrating perl script with main python script.
I have a perl script by name: GetHostByVmname.pl
./GetHostByVmname.pl –server 10.0.1.191 –username Administrator –password P@ssword1 –vmname RHTest
I need to call above script from my python main script. Tried below, but doesn’t work:
param = "--server 10.0.1.191 --username Administrator --password P@ssword1 --vmname RHTest"
pipe = subprocess.Popen(["perl", "./GetHostByVmname.pl", param ], stdout=subprocess.PIPE)
Upvotes: 3
Views: 6390
Reputation: 153
I think it will be better when you split string
./GetHostByVmname.pl –server 10.0.1.191 –username Administrator –password P@ssword1 –vmname RHTest
to a list, and after call Popen with this list as a first param. Example:
import shlex, subprocess
args_str = "./GetHostByVmname.pl –server 10.0.1.191 –username Administrator –password P@ssword1 –vmname RHTest"
args = shlex.split(args_str)
p = subprocess.Popen(args, stdout=subprocess.PIPE)
Upvotes: 2
Reputation: 385506
You can either provide a shell command
Popen("./GetHostByVmname.pl –server 10.0.1.191 ...", ...)
Or an array where the the first element is the program and the rest are args.
Popen(["./GetHostByVmname.pl", "–server", "10.0.1.191", ... ], ...)
Currently, you are doing the equivalent of the following shell command:
perl ./GetHostByVmname.pl '–server 10.0.1.191 ...'
Upvotes: 5