I am new to python,Need some help!
PYTHON VERSION: 2.7
SCRIPT
import subprocess
import sys
HOST="user@machine"
COMMAND="ps -fu user | grep \"XYZ\" |grep -v grep |wc -l" #Command to be run
ssh = subprocess.Popen(["ssh", "%s" % HOST, COMMAND],shell=False,stdout=subprocess.PIPE,stderr=subprocess.PIPE)
result = ssh.stdout.readlines()
if result == []:
error = ssh.stderr.readlines()
print >>sys.stderr, "ERROR: %s" % error
else:
result = [qaz.strip('\n') for qaz in result]
print result
This script results in this output:
['0']
PROBLEM
Even If change the COMMAND to be executed on other machine to some irrelevant string,I am not getting the error message ,say I change the command to below value and run the script again.
COMMAND="adsasdadsps -fu user | grep \"XYZ\" |grep -v grep |wc -l"
The script now also results in same output.
['0']
But When I changed the command as below.
COMMAND="asdadasd"
Then I got the output.
ERROR: ['ksh: line 1: asdadasd: not found\n']
Can anyone help with me understand why I am not getting error message for
COMMAND="adsasdadsps -fu user | grep \"XYZ\" |grep -v grep |wc -l"