This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Title: subprocess.check_output goes to infinte loop
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.6
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: eryksun, sanjay patel
Priority: normal Keywords:

Created on 2018-07-26 10:44 by sanjay patel, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (2)
msg322413 - (view) Author: sanjay patel (sanjay patel) Date: 2018-07-26 10:44
Below snipped goes to infinite loop when running through windows command prompt but works in python IDLE

import subprocess
subprocess.check_output('cmd.exe dir', stderr=subprocess.STDOUT)

in windows cmd use command: python
then it goes to infine loop but the same program works in Python IDLE.
msg322416 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2018-07-26 11:30
`cmd.exe dir` ignores the unrecognized `dir` argument and runs the interactive shell. The shell is waiting for input on stdin. You can type "exit" and press enter to return to Python.  

When you run this from IDLE (i.e. via pythonw.exe), there's no StandardInput handle to inherit, so subprocess executes cmd.exe with its stdin set to a closed pipe. (I don't know why a closed pipe is used. I think "NUL" would be better.) The shell exits immediately because ReadFile fails with ERROR_BROKEN_PIPE.
Date User Action Args
2022-04-11 14:59:03adminsetgithub: 78414
2018-07-26 11:30:00eryksunsetstatus: open -> closed

nosy: + eryksun
messages: + msg322416

resolution: not a bug
stage: resolved
2018-07-26 10:44:12sanjay patelcreate