I try to create a subprocess with Popen. Here is my code at first:
hostname = 'host'
servername = 'server'
commandargs = ['/usr/sbin/mminfo',' -o n',' -s',servername,' -q "client=\'',hostname,'\',savetime>=last day"',' -r "client,name"']
process = subprocess.Popen(commandargs, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
The problem is that the executed command failed with a message, that the contacted server is not available. It seems that the variable hostname is not used…
Trying the same with a string, instead of a list, as command in Popen (with Shell=True) everything is working fine.
Does anyone know what is wrong with the code?
Regards.
Stefan
Each string in the given list is handled as a single command line argument. You don’t need to use quotes when using this syntax either.
Try something like this:
EDIT: Or, based on comments, something like