Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

popenx() argument mangling hangs python #35088

Closed
rcamesz mannequin opened this issue Sep 1, 2001 · 3 comments
Closed

popenx() argument mangling hangs python #35088

rcamesz mannequin opened this issue Sep 1, 2001 · 3 comments
Assignees

Comments

@rcamesz
Copy link
Mannequin

rcamesz mannequin commented Sep 1, 2001

BPO 457466
Nosy @tim-one, @mhammond

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = 'https://github.com/mhammond'
closed_at = <Date 2002-04-03.01:52:24.000>
created_at = <Date 2001-09-01.01:16:40.000>
labels = ['OS-windows']
title = 'popenx() argument mangling hangs python'
updated_at = <Date 2002-04-03.01:52:24.000>
user = 'https://bugs.python.org/rcamesz'

bugs.python.org fields:

activity = <Date 2002-04-03.01:52:24.000>
actor = 'mhammond'
assignee = 'mhammond'
closed = True
closed_date = None
closer = None
components = ['Windows']
creation = <Date 2001-09-01.01:16:40.000>
creator = 'rcamesz'
dependencies = []
files = []
hgrepos = []
issue_num = 457466
keywords = []
message_count = 3.0
messages = ['6305', '6306', '6307']
nosy_count = 3.0
nosy_names = ['tim.peters', 'mhammond', 'rcamesz']
pr_nums = []
priority = 'normal'
resolution = 'fixed'
stage = None
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue457466'
versions = []

@rcamesz
Copy link
Mannequin Author

rcamesz mannequin commented Sep 1, 2001

[Platform: Windows 98, using Python 2.1.1]

Simple example: 
Python 2.1.1 (#20, Jul 20 2001, 01:19:29) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
>>> import os
>>> w,r = os.popen2('dir "C:\\Program Files\\*.*"')

I have found that under certain conditions popenx() (x = 2,3,4) will go to never-never land after
issuing a warning beep (Windows "attention sign"). I eventually tracked this down as being caused
by the fact that the commandline sometimes gets broken down into several parts when double
quotes and spaces are present in a certain way in popen's commandline parameter.

This prompts w9xpopen.exe to present an invisibe(!) warning mesagebox to the user, assuming it
was invoked manually. Being invisible means you can't click the OK-button, and Python grinds to a
halt without further warning. To get control back to the Python interpreter you have to press
return immediately *without* changing focus. If you do change focus, hitting CTRL-BREAK may be
your only option. Sometimes, the task will seemingly end, but actually won't. The CTRL-ALT-DEL
tasklist will show a 'W9xpopen' and 'Winoldapp' process active.

I am not sure if this bug can actually be fixed all that easily (I've read about similar problems for
spawnv()) but there are two things that can be done:

1 - Work around it. I've found that it's possible to escape the double quotes in the usual way (\")
and that works fine. For some strange reason it is also neccesary to escape _trailing_ backslashes
to \\, or else they are changed into a double quote. Very strange... (Don't forget to *double*
those backslashes in ordinary Python strings. I know, four of them at the and of a string does look
rather ugly.) Come to think of it, a bugfix within Python's nt-module might use a similar
escape-tactic, with some care.

2 - Modify w9xpopen.c slightly, so the error at least doesn't cause the invisible messagebox to pop
up. But I've gone a bit further and changed it so it printf's an error message if argc exceeds 2 and
then returns. Of course you can't actually *see* that error message, but Python can at least read
it from the one of the filehandles which popenx() returns, so it doesn't fail silently. I've attached
the modified w9xpopen.c to this bug report.

@rcamesz rcamesz mannequin closed this as completed Sep 1, 2001
@rcamesz rcamesz mannequin assigned mhammond Sep 1, 2001
@rcamesz rcamesz mannequin added the OS-windows label Sep 1, 2001
@rcamesz rcamesz mannequin closed this as completed Sep 1, 2001
@rcamesz rcamesz mannequin assigned mhammond Sep 1, 2001
@rcamesz rcamesz mannequin added the OS-windows label Sep 1, 2001
@tim-one
Copy link
Member

tim-one commented Sep 1, 2001

Logged In: YES
user_id=31435

Assigned to MarkH. popen on Win9x is a bottomless pit, and
Mark is more familiar with its depths than I am.

@mhammond
Copy link
Contributor

mhammond commented Apr 3, 2002

Logged In: YES
user_id=14198

Fixed. w9xpopen.exe should never display a message box,
and argument passing has been fixed so quoted args now work
correctly. Lib/test/test_popen.py added.

Checking in PC/w9xpopen.c;
/cvsroot/python/python/dist/src/PC/w9xpopen.c,v <--
w9xpopen.c
new revision: 1.3; previous revision: 1.2

Checking in Modules/posixmodule.c;
/cvsroot/python/python/dist/src/Modules/posixmodule.c,v <--
posixmodule.c
new revision: 2.227; previous revision: 2.226

Checking in Lib/test/test_popen.py;
/cvsroot/python/python/dist/src/Lib/test/test_popen.py,v <-

  • test_popen.py
    initial revision: 1.1

Checking in Lib/test/output/test_popen;
/cvsroot/python/python/dist/src/Lib/test/output/test_popen,v
<-- test_popen
initial revision: 1.1
done

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants