Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

calling perl script that takes multiple input args in python

Tags:

python

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)
like image 230
Srikar Avatar asked Apr 27 '26 02:04

Srikar


1 Answers

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 ...'
like image 74
ikegami Avatar answered Apr 28 '26 14:04

ikegami



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!