Issue 1463104: problems with os.system and shell redirection on Windows XP (original) (raw)
Issue1463104
Created on 2006-04-02 17:18 by manlioperillo, last changed 2022-04-11 14:56 by admin. This issue is now closed.
Messages (3) | ||
---|---|---|
msg28028 - (view) | Author: Manlio Perillo (manlioperillo) | Date: 2006-04-02 17:18 |
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 int main(int argc, char** argv) { std::system(argv[1]); } --------------------------------- there are no problems. Thanks and regards Manlio Perillo | ||
msg28029 - (view) | Author: Tim Peters (tim.peters) * ![]() |
Date: 2006-04-05 18:40 |
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 . 04/05/2006 02:29 PM .. 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 [options] [args] Subversion command-line client, version 1.2.3. [etc] | ||
msg28030 - (view) | Author: Manlio Perillo (manlioperillo) | Date: 2006-04-05 20:21 |
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! |
History | |||
---|---|---|---|
Date | User | Action | Args |
2022-04-11 14:56:16 | admin | set | github: 43148 |
2006-04-02 17🔞41 | manlioperillo | create |