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.

Author terry.reedy
Recipients Thekent, terry.reedy
Date 2011-04-15.20:47:38
SpamBayes Score 3.4613423e-11
Marked as misclassified No
Message-id <1302900461.16.0.730290368986.issue11820@psf.upfronthosting.co.za>
In-reply-to
Content
I am not sure if this should be called a bug or feature request, but that does not matter so much with IDLE. 

Os.system is documented as executing in a subshell and returning the exit code, which is does. The doc also says "If command generates any output, it will be sent to the interpreter standard output stream."

IDLE tries to imitate the interpreter, but it is not the interpreter, and I am not sure if that is always possible. The problem is that IDLE sends code (or, I presume, a filename) to a windowless interpreter (via socket or pipe) and receives and displays whatever is sent back. So I suspect the problem and fix is and would have to be with how a windowless interpreter executes os.system (in a third process). But for all I know, it may be the OS that decides not to hook the output of a system process to a no-window process that calls it.

On Windows, os.system('dir') ('dir' == 'ls') within IDLE pops up a command window to display the output, which immediately disappears. The same within the interactive interpreter (in a Command Prompt window) displays the output, just as with your XTerminal case.

Os.getcwd is documented as returning a string, so of course it does. It is not relevant to this issue.

Because of problems with os.system, the docs end with a suggestion to use subprocess instead. So there may be reluctance to 'fix' os.system calls.

The subprocess doc has an example for 'ls'. For 3.2 it is

>>> subprocess.check_output(["ls", "-l", "/dev/null"])
b'crw-rw-rw- 1 root root 1, 3 Oct 18  2007 /dev/null\n'

but the quotes and \n suggest that multiline output would not display properly.

On Windows with 3.2, the following works

>>> print(subprocess.check_output(['dir'], shell=True).decode())
 Volume in drive C is HP_PAVILION
 Volume Serial Number is 6C44-B700

 Directory of C:\Programs\Python32

shell=True is needed for 'dir' to be recognized.
Both print and .decode() are needed for proper line breaks.

The same info for the current directory is also available in an Open File or Save File dialog, so the ls/dir is really not needed.
History
Date User Action Args
2011-04-15 20:47:41terry.reedysetrecipients: + terry.reedy, Thekent
2011-04-15 20:47:41terry.reedysetmessageid: <1302900461.16.0.730290368986.issue11820@psf.upfronthosting.co.za>
2011-04-15 20:47:39terry.reedylinkissue11820 messages
2011-04-15 20:47:38terry.reedycreate