Python Forum
Subprocess command working for one cmd and for cmd one not wrking
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Subprocess command working for one cmd and for cmd one not wrking
#1
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
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Using subprocess to execute complex command with many arguments medatib531 5 1,719 Apr-27-2023, 02:23 PM
Last Post: medatib531
  use subprocess on linux\pi wwith a "grep " command korenron 2 7,904 Oct-19-2021, 10:52 AM
Last Post: DeaD_EyE
  Subprocess.Popen() not working when reading file path from csv file herwin 13 14,619 May-07-2021, 03:26 PM
Last Post: herwin
  Error when running mktorrent subprocess command pythonnewbie138 4 3,766 Sep-16-2020, 01:55 AM
Last Post: pythonnewbie138
  Select correct item from list for subprocess command pythonnewbie138 6 3,211 Jul-24-2020, 09:09 PM
Last Post: pythonnewbie138
  How to parallel executing a command using subprocess? larkypython 0 2,101 Nov-28-2019, 03:49 PM
Last Post: larkypython
  Long command with characters not working in Python on Oracle Linux 7 iaas_infra 10 6,128 Jul-19-2019, 04:53 PM
Last Post: ichabod801
  A question about subprocess taking input from command line and returning output! Aurimas 8 5,099 May-15-2019, 04:02 PM
Last Post: Aurimas
  Linux command output not working adam2020 2 2,654 Mar-23-2019, 01:20 PM
Last Post: adam2020
  t.onkey command isn't working PythonSnake 2 2,984 Jan-24-2019, 08:02 PM
Last Post: PythonSnake

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020