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

problems with os.system and shell redirection on Windows XP #43148

Closed
manlioperillo mannequin opened this issue Apr 2, 2006 · 3 comments
Closed

problems with os.system and shell redirection on Windows XP #43148

manlioperillo mannequin opened this issue Apr 2, 2006 · 3 comments
Labels
stdlib Python modules in the Lib dir

Comments

@manlioperillo
Copy link
Mannequin

manlioperillo mannequin commented Apr 2, 2006

BPO 1463104
Nosy @tim-one

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 = None
closed_at = <Date 2006-04-05.20:21:21.000>
created_at = <Date 2006-04-02.17:18:41.000>
labels = ['library']
title = 'problems with os.system and shell redirection on Windows XP'
updated_at = <Date 2006-04-05.20:21:21.000>
user = 'https://bugs.python.org/manlioperillo'

bugs.python.org fields:

activity = <Date 2006-04-05.20:21:21.000>
actor = 'manlioperillo'
assignee = 'none'
closed = True
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2006-04-02.17:18:41.000>
creator = 'manlioperillo'
dependencies = []
files = []
hgrepos = []
issue_num = 1463104
keywords = []
message_count = 3.0
messages = ['28028', '28029', '28030']
nosy_count = 2.0
nosy_names = ['tim.peters', 'manlioperillo']
pr_nums = []
priority = 'normal'
resolution = 'wont fix'
stage = None
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue1463104'
versions = []

@manlioperillo
Copy link
Mannequin Author

manlioperillo mannequin commented Apr 2, 2006

Python 2.4.3 (#69, Mar 29 2006, 17:35:34) [MSC v.1310
32 bit (Intel)] on win32 - Windows XP SP2

N.B. sorry for italian error messages.

With the following script:

# redirection.py
import os
import sys


os.system(sys.argv[1])

When doing:
redirection.py "dir" > redirection.txt

I obtain:
Spazio su disco insufficiente.

Instead with:
redirection.py "svn help" > redirection.txt

svn: Errore di scrittura: Bad file descriptor

This is a Python problem because with an equivalent
program written in C++:

// redirection.c++
#include <cstdlib>


int main(int argc, char** argv) {
  std::system(argv[1]);
    }

there are no problems.

Thanks and regards Manlio Perillo

@manlioperillo manlioperillo mannequin closed this as completed Apr 2, 2006
@manlioperillo manlioperillo mannequin added the stdlib Python modules in the Lib dir label Apr 2, 2006
@manlioperillo manlioperillo mannequin closed this as completed Apr 2, 2006
@manlioperillo manlioperillo mannequin added the stdlib Python modules in the Lib dir label Apr 2, 2006
@tim-one
Copy link
Member

tim-one commented Apr 5, 2006

Logged In: YES
user_id=31435

Sorry, there's nothing Python can do about this -- it's a
well-known family of Windows bugs, and affects all scripts
(regardless of language) that try to combine command line
I/O redirection with implicit determination of the
executable via file association. As you've discovered, it
doesn't effect .exe files (which is why your C++ example
isn't relevant). Various versions of Windows fail in
various ways, but in no version of Windows to date have all
the redirections bugs been fixed.

For example, here I'll reproduce your symptoms exactly with
Perl scripts on WinXP, although the error messages are English:

C:\Perl\bin>type blah1.pl
system("dir");

C:\Perl\bin>blah1.pl > out.txt
There is not enough space on the disk.

C:\Perl\bin>type blah2.pl
system("svn help");

C:\Perl\bin>blah2.pl > out.txt
svn: Write error: Bad file descriptor

The simplest and most reliable workaround is to put the path
to the executable first on the command line. Here are the
same Perl examples doing that; the same kind of thing works
for all cases in which Windows redirection doesn't work
(including, of course, Python):

C:\Perl\bin>.\perl blah1.pl > out.txt

C:\Perl\bin>type out.txt
Volume in drive C has no label.
Volume Serial Number is 5C0F-48E6

Directory of C:\Perl\bin

04/05/2006 02:29 PM <DIR> .
04/05/2006 02:29 PM <DIR> ..
02/04/2003 03:35 PM 90,175 a2p.exe
[etc]

C:\Perl\bin>.\perl blah2.pl > out.txt

C:\Perl\bin>type out.txt
usage: svn <subcommand> [options] [args]
Subversion command-line client, version 1.2.3.
[etc]

@manlioperillo
Copy link
Mannequin Author

manlioperillo mannequin commented Apr 5, 2006

Logged In: YES
user_id=1054957

Thanks for the detailed response.

As a joke, I have written this code at the begin of the script:

os.dup2(2, 3) # backup fd 2

os.dup2(1, 2)
os.dup2(2, 1)

os.dup2(3, 2) # restore fd 2

and it *seems* to work!

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir
Projects
None yet
Development

No branches or pull requests

1 participant