Python 2.7 - Quotes added to command when using Popen to execute from variable -


i'm trying send command through socket client server execute command on server , send output me. works fine if command 1 word no options. if use option such netstat -an or dir c:\ command isn't recognized , output looks quotes put around command before being executed ('"netstat -an"' not recognized internal or external command). know aren't saved in variable way because printed before being executed error check. please help. here code looks like:

commout = subprocess.popen([data], stdout=subprocess.pipe, shell=true)  (out, err) = commout.communicate() 

try make data array of arguments (the first being actual command).

for example:

commout = subprocess.popen(['netstat', '-an'], stdout=subprocess.pipe, shell=true) 

the first element string representing actual command (netstat), next element string representing first argument (-an).

to clarify, popen(['echo', 'a', 'b'] equivalent echo b on command line, whereas popen(['echo', 'a b'] equivalent echo "a b" instead (ie. single argument space between a , b.


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -