Message133873
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. |
|
Date |
User |
Action |
Args |
2011-04-15 20:47:41 | terry.reedy | set | recipients:
+ terry.reedy, Thekent |
2011-04-15 20:47:41 | terry.reedy | set | messageid: <1302900461.16.0.730290368986.issue11820@psf.upfronthosting.co.za> |
2011-04-15 20:47:39 | terry.reedy | link | issue11820 messages |
2011-04-15 20:47:38 | terry.reedy | create | |
|