~~David~~ has asked for the wisdom of the Perl Monks concerning the following question:

All, I have a Tk app that launches an external program via system.
system $exec_string if ( $AUTO_LAUNCH and $file_name );
This successfully launches my program, but the Tk GUI hangs until I exit out of the app. I know this is the documented behaviour of the system function.
My desired behaviour for this application is to launch the external program, keep it open for future manipulation, but allow the perl script to return and be able to launch another instance of the external program.
I have attempted using exec, but this completely closes down my script. I have tried eval'ing the exec, and that doesn't work. I have tried wrappig the exec in another block, and I couldn't get that to work either. I read about IPC::Cmd, and I couldn't get that to work either.
Is it possible to do what I want? Can someone point me to references on how to accomplish this?
Thanks, David

Replies are listed 'Best First'.
Re: Launch External App in Tk And Return
by GrandFather (Saint) on Sep 29, 2010 at 21:35 UTC
      I tried using fork, but I don't really understand this. I am on Win, and I was under the impression the Tk was not threadsafe... I can try, though...

      Thanks, David

        Since you're using 'system', I presume that the external app in question can be launched via command prompt. In that case, you've got an easy solution. Just add "start " to the front of what you're sending into 'system'. This will tell Windows to run the rest of the command in a new "space" and will immediately return control back to your script.

        For example, if you were launching notepad, you could do it with the following line of code:

        system("notepad");

        That would cause the script to wait until notepad was closed. Instead, modify it to be like this:

        system("start notepad");

        You'll see a command prompt appear, notepad gets opened, the command prompt disappears, and your script continues on. Just apply this to your script/app code in launching the external app and you should be good to go.

        If you want to know more about the various options for the 'start' command, just open a command prompt and type start /? to see the help information.

Re: Launch External App in Tk And Return
by ww (Archbishop) on Sep 30, 2010 at 01:29 UTC
    Unclear:

    Do you want the 'external program' to return data to the Tk GUI ap (which then mungs that data or consolidates the output of 'external program' to a single file)
    -- or -- some other alternative not mentioned here?

    ... or are you iterating over the members of a set of records (construed very loosely) with one complete run of the 'external program' required per data point (perhaps, manually input or selected via the Tk GUI)?

    If not, does the Tk GUI exist merely to protect users from the terrors of the command line interface?

    You have several suggestions on how to do what you've asked about, but it would be easier to offer actual help if you provided details of the interaction (if any) between what the 'external program' does and what your Tk GUI tries to do.

Re: Launch External App in Tk And Return
by zentara (Cardinal) on Sep 30, 2010 at 10:28 UTC
Re: Launch External App in Tk And Return
by Anonymous Monk on Sep 29, 2010 at 21:30 UTC