Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

How do you start an application from perl? Or maybe the question is is this possible?

Replies are listed 'Best First'.
Re: Opening Apps
by ivey (Beadle) on Jun 06, 2000 at 22:43 UTC
    Several solutions

    If you care about the program's output, use backticks, like so:

    my $result = `ls /home`; print $result;
    Otherwise, you can use system:
    system('cp /tmp/foo /tmp/bar') || die "Can't run command";
    (although you should NEVER use cp when you can roll your own in perl)

    Also, go see the thread on Running External Commands that has another method (pipe opens), plus valuable info on taint checking.

Re: Opening Apps
by infoninja (Friar) on Jun 06, 2000 at 22:40 UTC
Re: Opening Apps
by Shendal (Hermit) on Jun 06, 2000 at 23:06 UTC
    I think a more appropriate question would be, "What are you trying to do?" As ivey alluded to above, sometimes it's better to "roll your own in perl."
    For example, when I was first learning, I kept using somethine like ls with backticks, when opendir is a much better way to get at this information.
    HTH.
(zdog) Re: Opening Apps
by zdog (Priest) on Jun 06, 2000 at 22:37 UTC
    I have never used it and I am not sure if it is exactly what you want, but check and see perlfunc:system.

    Good Luck!

    -- zdog (Zenon Zabinski)
       Go Bells!!

Re: Opening Apps
by Anonymous Monk on Jun 07, 2000 at 00:07 UTC
    I am trying to create a program that will launch several applications for myself in Windows 95. So that I can click on one program and it'll launch my browser, my graphics editor, my text editor, and so on. I want to accomplish this by using an external file that I can somehow store the information into variables so that I can compile the program and still be able to edit it.
      Look at using the Win32::Process module. It's the only way you are going to be able to launch several applications at once on Win32 without using Perl 5.6 and some fork()ing.

      The other methods that have been mentioned in this thread will force your program to wait until the launched application closes before it can continue running, which isn't a desirable side-effect if you are programming an application launcher.

      do like what was suggested before:
      my $val1=`notepad.exe`; my $val2=`program2.exe`; . . .
      or put the names of the programs into a txt file and run through it.
      ***progs.txt**** notepad.exe paint.exe . . .
      then have a script to do this
      open(INPUTFILE, "progs.txt"); while(<INPUTFILE>){ $val=`print`; }
      This was not tested but would be where I would start.

      --Big Joe
        I don't think that this works
        open(INPUTFILE, "progs.txt"); while(<INPUTFILE>){ $val=`print`; }
        because I don't think you can issue a perl print inside of backticks.