Reputation: 21
I want to run an exe from my perl script which is not in the same directory where my perlscript exist. As well as the directory is not in the system PATH. How to set the path in the perl itself and run that exe. I tried to set env but it didnt work.
thnx, kas
Upvotes: 0
Views: 5937
Reputation: 2303
You shouldn't need to set any environment variables just to run an exe. All you need to do is run the exe using its absolute path or a path relative to the directory you are in when you execute the perl script. For example, assuming this is Windows (since you're talking about an exe) if you have a directory structure like:
C:
- dira
| - a.exe
- dirb
- dirc
- a.pl
and at your command prompt you are running:
C:\dirb>perl dirc\a.pl
then in your perl file, you should use either
`C:\\dira\\a.exe`;
or
`..\\dira\\a.exe`;
If your command prompt is:
C:\dirb\dirc>perl a.pl
then you can use
`C:\\dira\\a.exe`;
or
`..\\..\\dira\\a.exe`;
Update
file test.pl:
$ENV{'PATH'}.= ':some/dir';
system('./testpath.pl');
file testpath.pl:
open(FILE, '>>output.txt');
print FILE $ENV{'PATH'};
close(FILE);
Upvotes: 1
Reputation: 13906
If you know where the exe file is, just use the path to it the same as if you were running it from the command line. In Perl:
system('c:\full\path\to\exe\program.exe');
or if you prefer to use forward slashes (they're all the same to the Windows kernel):
system('c:/full/path/to/exe/program.exe');
Upvotes: 2
Reputation: 274612
Try using the full path to your exe. e.g.
system("/full/path/to/app.exe");
Did you set your path like this:
To get your PATH:
$path = $ENV{'PATH'};
To set it:
$ENV{'PATH'} = 'some/dir:another/dir';
Upvotes: 3