Subprocess.Popen () => No output

I am trying to run a Perl script from Python, but I am not getting any output in stdout (), and my script works fine when I run it from the shell.

First, here's how I run it from the shell (suppose I'm in the right directory):

./vmlinkedclone.pl --server 192.168.20.2 --username root --password root --vmbase_id 2 --vm_destination_id 41 --vmname_destination "clone-41-snapname" --snapname Snapname #=> True, [] #=> or False, and a description of the error here #=> or an argument error 

And this is how I try to call it from Python:

 cmd = ['/home/user/workspace/vmlinkedclone.pl', '--server', '192.168.20.2', '--username', 'root', '--password', 'root' ,'--vmbase_id', '2', '--vm_destination_id', '41', '--vmname_destination', 'clone-41-snapname', '--snapname', 'Snapname'] pipe = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE) result = pipe.stdout.read() print "Result : ",result #=> Result : 

Why do I get the desired result when I run my script from Shell and get nothing from Python?

+6
source share
1 answer

Can you just try:

 pipe = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) 

Edit

I once discovered some encoding issues and I solved it as follows:

 import subprocess cmd = ['/home/user/workspace/vmlinkedclone.pl', '--server', '192.168.20.2', '--username', 'root', '--password', 'root' ,'--vmbase_id', '2', '--vm_destination_id', '41', '--vmname_destination', 'clone-41-snapname', '--snapname', 'Snapname'] pipe = subprocess.Popen(cmd, shell = True, stdout=subprocess.PIPE, stderr=subprocess.PIPE) out, err = pipe.communicate() result = out.decode() print "Result : ",result 
+7
source

All Articles