start external program from python

Discussion in 'Python' started by Bjorn, Oct 12, 2009.

  1. Bjorn

    Bjorn Guest

    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
    Bjorn, Oct 12, 2009
    #1
    1. Advertising

  2. Bjorn

    TerryP Guest

    On Oct 12, 10:15 am, 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'
    > 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.
    TerryP, Oct 12, 2009
    #2
    1. Advertising

  3. Bjorn

    Jorgen Grahn Guest

    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'
    > 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

    --
    // Jorgen Grahn <grahn@ Oo o. . .
    \X/ snipabacken.se> O o .
    Jorgen Grahn, Oct 12, 2009
    #3
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kristina Foxwell

    Start external process from ASP.Net

    Kristina Foxwell, Jul 10, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    436
    Steve C. Orr, MCSD
    Jul 10, 2003
  2. Shawn Anderson
    Replies:
    7
    Views:
    669
    =?Utf-8?B?TWFyayBEdXJlZ29u?=
    Jul 14, 2004
  3. Replies:
    4
    Views:
    30,675
    Rhino
    Nov 7, 2005
  4. Scott Allen
    Replies:
    8
    Views:
    10,907
    Scott Allen
    May 2, 2004
  5. Mellow Crow
    Replies:
    6
    Views:
    410
    Richard Cornford
    Nov 4, 2005
Loading...

Share This Page