Python Forum
Subprocess command working for one cmd and for cmd one not wrking - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Subprocess command working for one cmd and for cmd one not wrking (/thread-25276.html)



Subprocess command working for one cmd and for cmd one not wrking - PythonBeginner_2020 - Mar-25-2020

Hi All,
i hame on simple code.
same code is working when i am using customer specific tool command . but same code is not working on other command,
example:-
mycommand1 --is working, with in python and on window cmd prompt when i test it manually
mycommand2 --is not working in python , but working on cmd prompt but its taking 20-40 second to exceute on command prompt while testing it manually ,is it because of delay this code is not working on mycommand2 ?

import subprocess as sp
a=sp.run('mycommand',shell = True)
rc=a.returncode
print("This is returen code {}".format(rc))
if (rc==0):
    print("Command working fine")
    output = sp.run('mycommand',capture_output = True, text = True)
    print(output.stdout)
    
else:
    print("There is error in this  command")
-------------
Error:
Error output = sp.run('opcagt',capture_output = True, text = True) File "C:\Python38-32\lib\subprocess.py", line 489, in run with Popen(*popenargs, **kwargs) as process: File "C:\Python38-32\lib\subprocess.py", line 854, in __init__ self._execute_child(args, executable, preexec_fn, close_fds, File "C:\Python38-32\lib\subprocess.py", line 1307, in _execute_child hp, ht, pid, tid = _winapi.CreateProcess(executable, args, FileNotFoundError: [WinError 2] The system cannot find the file specified