[ python-Bugs-1463104 ] problems with os.system and shell redirection on Windows XP

SourceForge.net noreply at sourceforge.net
Wed Apr 5 22:21:22 CEST 2006


Bugs item #1463104, was opened at 2006-04-02 17:18
Message generated for change (Comment added) made by manlioperillo
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1463104&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: 3rd Party
Status: Closed
Resolution: Wont Fix
Priority: 5
Submitted By: Manlio Perillo (manlioperillo)
Assigned to: Nobody/Anonymous (nobody)
Summary: problems with os.system and shell redirection on Windows XP

Initial Comment:
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

----------------------------------------------------------------------

>Comment By: Manlio Perillo (manlioperillo)
Date: 2006-04-05 20:21

Message:
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!


----------------------------------------------------------------------

Comment By: Tim Peters (tim_one)
Date: 2006-04-05 18:40

Message:
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]


----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1463104&group_id=5470


More information about the Python-bugs-list mailing list