start external program from python

B

Bjorn

Hi, I woul like to start a program from within python (under linux):
This works fine:

import os
path = 'tclsh AppMain.tcl hej.gb'
os.system(path)

The file AppMain.tcl is the executable and the file hej.gb is a
textfile in the same directory.
The text file gets opened in the app in the correct way.

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!
/bjorn
 
T

TerryP

Hi, I woul like to start a program from within python (under linux):
This works fine:

import os
path = 'tclsh AppMain.tcl hej.gb'
os.system(path)

The file AppMain.tcl is the executable and the file hej.gb is a
textfile in the same directory.
The text file gets opened in the app in the correct way.

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!
/bjorn

Option A.) Use a program such as xclip or xcb to pipe the clipboard
data into AppMain.tcl

Option B.) Make your Python program able to get/set the clipboard at
will, then set it before calling the program. Do like wise with
AppMain.tcl but have it get the clipboard.

Option C.) Create some external program that can do the B dance for
them.


Using option A takes advantage of your use of os.system, because it
delegates to the shell. if going for option B, you should probably
look at avoiding use of the shell at all (look at args to the
subprocess module).

Bonus points if you can think of an Option D.
 
J

Jorgen Grahn

Hi, I woul like to start a program from within python (under linux):
This works fine:

import os
path = 'tclsh AppMain.tcl hej.gb'
os.system(path)

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

http://en.wikipedia.org/wiki/Shebang_(Unix)

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top