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.

classification
Title: Executing Python script using subprocess.Popen twice interactively fails without error the second time
Type: behavior Stage:
Components: Windows Versions: Python 2.5
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: amaury.forgeotdarc, canhuth
Priority: normal Keywords:

Created on 2007-11-30 10:00 by canhuth, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (3)
msg57971 - (view) Author: (canhuth) Date: 2007-11-30 10:00
Executing script using subprocess.Popen twice interactively fails
without error the second time. File a.py:

print "start"
import subprocess

print "first call"
process = subprocess.Popen(
	args   = "cmd.exe /c echo 1",
	stdout = subprocess.PIPE)

for line in process.stdout:
	if not line:
		break;
	print line;

print "second call"
process = subprocess.Popen(
	args   = "cmd.exe /c echo 2",
	stdout = subprocess.PIPE)

for line in process.stdout:
	if not line:
		break;
	print line;

print "end"

Executing it in Python on Windows, interactively:

Python 2.5.1 (r251:54863, Apr 18 2007, 08:51:08) [MSC v.1310 32 bit
(Intel)] on
win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import a
start
first call
1

second call
2

end
>>> import a
>>>
msg57974 - (view) Author: Amaury Forgeot d'Arc (amaury.forgeotdarc) * (Python committer) Date: 2007-11-30 11:11
Top-level statements are executed only the first time the module is
imported:
http://docs.python.org/tut/node8.html#moreModules
To execute a script from python, you should consider the execfile()
function instead.
msg57976 - (view) Author: (canhuth) Date: 2007-11-30 11:29
Bah, silly me, I apologize, and thank you for the quick feedback.
History
Date User Action Args
2022-04-11 14:56:28adminsetgithub: 45866
2007-11-30 11:29:39canhuthsetmessages: + msg57976
2007-11-30 11:11:09amaury.forgeotdarcsetstatus: open -> closed
resolution: not a bug
messages: + msg57974
nosy: + amaury.forgeotdarc
2007-11-30 10:00:44canhuthcreate