in reply to Re: how to open a separate notepad
in thread how to open a separate notepad

system will wait for notepad to finish executing before the Perl code continues. If you wanted to just launch notepad and continue then you would use exec.

Similarly if you just wanted to start the default application then you can omit the program and just exec the file. In this situation, exec may be essential because the default editor may support multiple documents and the user wouldn't necessarily want to close it. The Perl application won't have to wait.

#launch notepad explicitly exec ("notepad $path_to_text_file"); # or launch the default application exec ("$path_to_text_file");

Replies are listed 'Best First'.
Re^3: how to open a separate notepad
by GrandFather (Saint) on Jul 22, 2005 at 09:41 UTC

    exec is not such a good choice as it does not return. Click the first button, and that's all she wrote mate.

    Best answer probably is to simply open another top level Tk window to display the text for the additional file.

    I'm a newbie at Tk so I can't provide good code to do that, but it's likely to be fairly easy. Maybe I'll try after I've done the shopping :)


    Perl is Huffman encoded by design.
Re^3: how to open a separate notepad
by davorg (Chancellor) on Jul 22, 2005 at 10:02 UTC

    I think you mean "fork" and then "exec" in the new child process.

    --
    <http://www.dave.org.uk>

    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

      You are entirely correct. I was testing with a one-liner (perl -e "exec('test.txt')") which doesn't point out that you never reach the line following the exec (because there isn't one!). Unfortunately, system by itself doesn't help because the Perl script is left waiting for notepad (or your favourite editor) to return.

      thundergnat provides the answer by modifying the command line to use the windows start command. This appears to be equivalent to the UNIX trailing apostrophe.

      print "This happens before\n"; system ("start test.txt"); print "This happens afterwards\n";