Re: [Python-ideas] Option of running shell/console commands inside the REPL

Hi, As a workaround/alternative, you can just do >>> import os >>> os.system('dir') Sincerely, Ken Hilton;

On 2/1/2019 9:24 AM, Ken Hilton wrote:
For repeated use within and between sessions, put 'from os import system as oss' in a startup file. Then one only needs "oss('dir')". Note that 'dir' only works on Windows; the unix equivalent is 'ls'. However this will not work in a gui IDE without special handling in the IDE. This docstring for os.system says "Execute the command in a subshell." (It should say "Execute the command in a subshell and return the exitcode.") I presume that this docstring assumes that one is running python is a system shell and that the subshell is a 'sub' of the system shell. Anyway, the subshell expects the output, in this case, a directory listing, to go to an attached system console. If one enters the above in IDLE's shell, the output does not appear in IDLE's shell. If one started IDLE in a terminal with 'python(3) -m idlelib', it goes to that terminal. Otherwise, it goes to a subshell which immediately closes and which may or may not flash on the screen. -- Terry Jan Reedy

On Fri, Feb 01, 2019 at 04:15:06PM -0500, Terry Reedy wrote:
Actually, on some Unix/Linux systems, ``dir`` is either an alias to ``ls``, or a similar but separate executable: [steve@ando ~]$ which dir /usr/bin/dir (TIL that dir can be a seperate executable... I was convinced it was only an alias until I tried it just now.) -- Steve

On 2/1/2019 9:24 AM, Ken Hilton wrote:
For repeated use within and between sessions, put 'from os import system as oss' in a startup file. Then one only needs "oss('dir')". Note that 'dir' only works on Windows; the unix equivalent is 'ls'. However this will not work in a gui IDE without special handling in the IDE. This docstring for os.system says "Execute the command in a subshell." (It should say "Execute the command in a subshell and return the exitcode.") I presume that this docstring assumes that one is running python is a system shell and that the subshell is a 'sub' of the system shell. Anyway, the subshell expects the output, in this case, a directory listing, to go to an attached system console. If one enters the above in IDLE's shell, the output does not appear in IDLE's shell. If one started IDLE in a terminal with 'python(3) -m idlelib', it goes to that terminal. Otherwise, it goes to a subshell which immediately closes and which may or may not flash on the screen. -- Terry Jan Reedy

On Fri, Feb 01, 2019 at 04:15:06PM -0500, Terry Reedy wrote:
Actually, on some Unix/Linux systems, ``dir`` is either an alias to ``ls``, or a similar but separate executable: [steve@ando ~]$ which dir /usr/bin/dir (TIL that dir can be a seperate executable... I was convinced it was only an alias until I tried it just now.) -- Steve
participants (3)
-
Ken Hilton
-
Steven D'Aprano
-
Terry Reedy