3

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)
1
  • the above code threw an error like this: Unknown option: server 10.0.1.191 --username Administrator --password P@ssword1 --vmname RHTest For a summary of command usage, type './GetHostByVmname.pl --help'. For documentation, type 'perldoc ./GetHostByVmname.pl'. Commented Apr 23, 2013 at 14:16

2 Answers 2

5

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 ...'
Sign up to request clarification or add additional context in comments.

1 Comment

thank you very much. I tested the solution from Alexey. But essentially both your solutions are the same.
2

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)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.