This program won't do what you want for a number of reasons:

  1. In spite of people telling you to use -w and use strict; there are no 'my' keywords in front of the @file or $line variables, so the program won't even try to run.
  2. system() does not do what you expect. Unless the program you're calling explicitly detaches itself as a process internally, only the first program will execute, because system() will be waiting for the program to execute before starting the next item.
  3. I don't know about ActiveState and any of the other builds, but the build of 5.005_03 under NT, if you don't encapsulate paths with spaces in quotes, the program won't be found. You either need to include quotes in the string, programatically, before calling system(), alter your data to have quotes around the strings in the 'location.txt' file, or use (gag!) 8.3 filename nomenclature. NT is smart enough, however, to not care about the direction of the path slashes (CMD.EXE cares, but the system internally does not, and really hasn't since about DOS 5.0 or so), and we can add the quotes programmatically, so we'll do that.
  4. The @file and $line variables could be eliminated. I was debating if there was any merit in reading the lines before executing them, and I can't find any compelling reason to do so before executing them.
  5. You could optionally include the data with the program. Depending on the programming methodology you subscribe to, some call for separating the data from the program to the extent that you should be using mySQL with a browser interface to update the paths. Or, if this is a utility script, and you don't like unnecessary data files cluttering up your disk, and you want to make *sure* there is some data within the program, you can include it as part of the program, in a __DATA__ section. I'll take this tact, since you're probably not going to be making a CPAN submission.

So, with all this in mind, here is a version that should do what you want. It works on my NT 4.0/SP6a system using Perl 5.005_03, with no problems. (side note here: The actual path to the perl executable is irrelevant. However, you need *something* there so that the compiler picks up the -w flag. Don't be concerned that there is no '/usr/bin/perl' path on your system.)
#!/usr/bin/perl -w use strict; while (<DATA>) { chomp; system ("start \"$_\" \"$_\"") && die "Can't execute $_\n"; } __DATA__ c:/program files/netscape/communicator/program/netscape.exe c:/Program Files/Netscape/Communicator/Winamp/winamp.exe c:/Program Files/Netscape/Communicator/Program/AIM/aim.exe
Why does this work, you might ask, after telling you that system() won't return until the called program completes? Because we're taking advantage of a little known fact that the 'shell' (such as it is) supports the 'start' keyword, which allows processes to be detached from the calling shell. The first parameter is the name of the program in the DOS box, and the second parameter is the program to execute. We technically could leave the first one blank, but I chose not to as I was debugging, and I saw no reason to leave it out. Supposedly, we could have omitted it, and used the /PGM switch, but I was getting errors. Since adding the window name fixed it, I didn't have any reason to pursue it any further.

In this version, chomp() is required because the 'shell' gets very upset if you pass a carriage return into it. What you'll end up with is 3 open DOS boxes, with the window name as the name of the program you're trying to execute.

Hopefully, this should do what you want. For testing, I have to change the names of the paths, and I don't have AIM installed (I used FreeCell instead), but I do have the rest. It all started up for me, just fine. Hopefully, it will work for you.

--Chris

e-mail jcwren

In reply to (jcwren) RE: loading by jcwren
in thread loading by elusion

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.