Python subprocess call cannot take grep
问题 Python subprocess call is supposed to run as command as is, but it is complaining if there is a pipe in it. Here is my code: #!/usr/bin/python import sys import subprocess import time service_name= "mysrvc" state ="STOPPED" mycmd ="sc query " + service_name + " " + "|" + " findstr" + " " + state print(mycmd) if subprocess.call(mycmd)==0: print("Service stopped successfully") The Error I get is : ERROR: Invalid Option; Would you like to see help for the QUERY and QUERYEX commands? [ y | n ]: