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



On Apr 30, 4:32 am, 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.

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é

Well,

You need to check sys.platform on the Mac instead of os.name.
os.name returns 'posix' on all *nix based systems. sys.platform
helpfully returns "darwin" on the Mac.

Not sure how to start Terminal. Here's what I got when I tried it:

if sys.platform == "darwin": os.spawnlp(os.P_NOWAIT, '/Applications/Utilities/Terminal.app/Contents/MacOS/Terminal')
9460
2007-04-30 05:19:59.255 [9460] No Info.plist file in application bundle or no NSPrincipalClass in the Info.plist file, exiting

Maybe I'm just calling it wrong and you'll have more luck.

Prateek

.



Relevant Pages

  • 15 reasons Macs are still better than Windows PCs
    ... With Windows 7 coming up, it's time to yet again ponder on whether ... I long ago stopped actively seeking out Mac vs PC discussions (partly ... Apple uses good quality parts. ... problem lies from those three apps. ...
    (comp.sys.mac.advocacy)
  • Re: Apple Notebook
    ... die gerne mit Unix Befehlen arbeiten und sich freuen, ... mich stören weder UNIX-Befehle (neben Mac OS X benutze ich selbst z.B. u.A. auch HP-UX, UNIX ist für mich also kein Fremder) noch Leute, die mit ihrem Mac zufrieden sind. ... Mich stört auch nicht, dass Windows mit Ausnahme von Windows Server 2003 R2 keine UNIX-Befehle kann, genauer gesagt geht mir das ziemlich am Allerwertesten vorbei, einfach weil der Bedarf nicht vorhanden ist. ... Und das nicht nur deswegen, weil Apple schlichtweg keinen professionellen Support anbietet, sondern weil die Masse der wichtigen Anwendungen eben nicht unter Mac OS X läuft, sondern unter Windows oder allenfalls noch Linux. ...
    (de.comp.sys.notebooks)
  • Re: I really do like OS X but . . .
    ... I think he was pointing out that Microsoft has to ensure backwards compatibility with the older MS-DOS based versions of Windows, which introduces a number of problems. ... But, of course, Mac users have no choice but to upgrade... ... support perspective too. ... even going to try to claim the PPC port of gcc is anywhere near as good ...
    (comp.sys.mac.advocacy)
  • Re: 15 reasons Macs are still better than Windows PCs
    ... 15 reasons Macs are still better than Windows PCs ... With Windows 7 coming up, it's time to yet again ponder on whether ... Microsoft has the upper hand in operating systems. ... I long ago stopped actively seeking out Mac vs PC discussions (partly ...
    (comp.sys.mac.advocacy)
  • Re: Aqua is a Plastic Cube!
    ... if WPF were put into Apple's old Mac OS X ... the problem this platform has is that it's rather vaguely defined, ... better than it is on X Windows or Windows XP. ...
    (comp.sys.mac.advocacy)