[email protected]
[Top] [All Lists]

Re: system call with path to executable

Subject: Re: system call with path to executable
From: Paul Appleby
Date: Thu, 16 Dec 2004 17:04:44 -0500

Thanks for the input.

Your first suggestion didn't work: system( 'C:/inetpub/web/sub', 'arg1', 'arg2' ) == 0;

But your second, of course did.

Is there a reason you didn't just add the sub's path to the PATH using concatenation? It worked for me.

These next three lines worked perfectly, although the second line is not necessary:
$ENV{'PATH')=~s%\\%/%g;  ### Not really needed.
system (anyprogram.exe arg1");

I don't think I need the original PATH info while this script runs. So *adding* the sub's path may be unnecessary, when just setting the PATH to the sub's path may be sufficient.


Paul Appleby wrote:

I tried your suggestions, but they didn't work.

I did, however, manage to come up with two solutions.

The first is the simplest. And that just involves setting the PATH environment variable to the absolute path of the subdirectory where the executable resides and then doing the system call to the executable. The system call will now be able to find the executable.

system (anyprogram.exe arg1");

One other thing you might try. C<system>, unfortunately, behaves different depending on its arguments, whether you pass a single string or multiple arguments and whether the string contains shell meta characters, amoung other things. It seems to work more reliably and predictably if you always use the LIST form:

system( 'C:/inetpub/web/sub', 'arg1', 'arg2' ) == 0
  or die( "system call failed: $?" );

just a WAG.


BTW, if you do go with the c<$ENV{PATH}> solution you mentioned, it's generally a good practice to localize the scope of variables as much as possible:

  require Config;
  local $ENV{'PATH'} = join( $Config::Config{path_sep},
                             ($ENV{PATH}, 'C:/inetpub/web/sub') );
  system( 'program.exe', 'arg1' );


Paul Appleby

(416) 530-0070
ActivePerl mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs

<Prev in Thread] Current Thread [Next in Thread>