start external program from python
grahn+nntp at snipabacken.se
Mon Oct 12 21:47:46 CEST 2009
On Mon, 2009-10-12, Bjorn wrote:
> Hi, I woul like to start a program from within python (under linux):
> This works fine:
> import os
> path = 'tclsh AppMain.tcl hej.gb'
> The file AppMain.tcl is the executable
Not really -- tclsh is the executable from Python's and the system's
view. If you are on Unix, you might want to use a shebang
and rename AppMain.tcl AppMain so you don't have to rewrite your
Python program just because you rewrite the Tcl program in some
other (more modern) language.
> and the file hej.gb is a
> textfile in the same directory.
> The text file gets opened in the app in the correct way.
So the subject line doesn't really capture your question?
> I wonder if I could pass information from the clipboard to the
> AppMain.tcl instead of the file hej.gb ?
> I use wxPython.
> any comment is appreciated!
Sure you can, but the clipboard wasn't really designed for that.
You can document 'AppMain' as taking its input from whatever is in the
clipboard when it starts, but if there is nothing there it cannot wait
for it, and there are no guarantees that the user or some other
program (or another copy of the program) hasn't put something else
there in the milliseconds it takes to start AppMain. It's also not a
private channel; any other program can read it.
Why do you want to use the clipboard?
If you think you need it because you don't want a temporary file,
maybe you can let AppMain read from standard input, and let the Python
program write the data using os.popen or one of the alternatives.
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
More information about the Python-list