Command framed to identify if Xcode is running on Mac: cmd = "ps -ax | grep -v grep | grep Xcode"
If Xcode is not running, then above command works well with Popen
method of subprocess
module, but raises a CalledProcessError
with check_output
method. I tried to inspect the stderr
through the following code, but failed to get appropriate information to understand the reason.
from subprocess import check_output, STDOUT, CalledProcessError
psCmd = "ps -ax | grep -v grep | grep Xcode"
o = None
try:
o = check_output(psCmd, stderr=STDOUT, shell=True)
except CalledProcessError as ex:
print 'Error:', ex, o
Exception message is as follows:
Error: Command 'ps -ax | grep -v grep | grep Xcode' returned non-zero exit status 1 None
Question: Why the above command works with Popen, but fails with check_output ?
Note: Command works well with both approach, if Xcode is running.