Re: Launching an independent Python program in a cross-platform way (including mac)



On Apr 29, 8:32 pm, André <andre.robe...@xxxxxxxxx> wrote:
I would like to find out how I can launch an independent Python
program from existing one in a cross-platform way. The result I am
after is that a new terminal window should open (for io independent of
the original script).

The following seems to work correctly under Ubuntu and Windows ... but
I haven't been able to find a way to make it work under Mac OS.


Forgot to add that there was an import as follows:

import os # should have been obvious
from subprocess import Popen # slightly less so


def exec_external(code, path):
"""execute code in an external process
currently works under:
* Windows NT (tested)
* GNOME (tested) [January 2nd and 15th change untested]
This also needs to be implemented for OS X, KDE
and some form of linux fallback (xterm?)
"""
if os.name == 'nt':
current_dir = os.getcwd()
target_dir, fname = os.path.split(path)

filename = open(path, 'w')
filename.write(code)
filename.close()

if os.name == 'nt':
os.chdir(target_dir) # change dir so as to deal with paths
that
# include spaces
Popen(["cmd.exe", ('/c start python %s'%fname)])
os.chdir(current_dir)
elif os.name == 'posix':
try:
os.spawnlp(os.P_NOWAIT, 'gnome-terminal', 'gnome- terminal',
'-x', 'python', '%s'%path)
except:
raise NotImplementedError
else:
raise NotImplementedError
==========================
Any help would be greatly appreciated.

André


.



Relevant Pages

  • Re: Command line vs KDE
    ... > takes me directly into KDE and I want to work at the command line as I ... If you are in X Windows, you can start a terminal and issue the commands ... Using a terminal window with the X environment allows you to do pretty much ...
    (alt.os.linux.suse)
  • Launching an independent Python program in a cross-platform way (including mac)
    ... I would like to find out how I can launch an independent Python ... after is that a new terminal window should open (for io independent of ... The following seems to work correctly under Ubuntu and Windows ... ... raise NotImplementedError ...
    (comp.lang.python)
  • Re: table editing application
    ... Most of my admin work is done via ssh in a terminal window, ... For those of you not familiar with Curses, it is a library of screen ... I wrote the app ... I work mostly inside xterm windows, with a need to frequently browse/edit ...
    (perl.dbi.users)
  • Re: Why do the escape sequences not work?
    ... > emulation support for terminals such as DEC VTxxx or ISO 6429. ... > this package also means that your program no longer has to use the ... > 'console' subsystem of Windows. ... This terminal window implements full VTxxx terminal ...
    (comp.lang.ada)
  • Re: Neat utilities
    ... Visor is a SIMBL plug-in that lets you drop down a Terminal window with ... access it with just a keystroke and then have it disappear entirely when ... What "severe limitations of the Mac GUI"? ... else (especially Windows) so far out of the water, ...
    (comp.sys.mac.advocacy)