revanth rev
revanth rev

Reputation: 3

Issue with Full path .exe in PERL

I'm working on a script where I'm using the .exe full path and a command relate to that exe.

For Example:

Path is C:\Documents and Settings\xx\My Documents\utils.exe

command is dir |findstr -i xx |findstr -i tr

My perl code is

$command='dir |findstr -i xx |findstr -i tr;
$path=C:\Documents and Settings\xx\My Documents\utils.exe
$result= `$path $command`;

I have tried many things like system, push @cmd,have gone through many blogs in google, but I'm really not able to find our any solution on this.

Could somebody please help me with this?

Upvotes: 0

Views: 63

Answers (1)

AdrianHHH
AdrianHHH

Reputation: 14047

If you expand out the code you get (assuming there should be a closing ' on the $command= line).

$result= `C:\Documents and Settings\xx\My Documents\utils.exe dir |findstr -i xx |findstr -i tr`;

Note the space characters. They mean Perl is trying to run the program C:\Documents with arguments and Settings\xx\My Documents\utils.exe dir and pipe that into findstr.

Quoting the executable name should help with making the exe run:

$result= `"$path" $command`;

Another possibility is to change the working directory to C:\Documents and Settings\xx\My Documents and then run the program with:

$result= `utils.exe $command`;

Upvotes: 1

Related Questions