How to run an executable file using Perl on Windows XP?
10,256
Solution 1
Try this.
my $prog = "C:\\strawberry\\perltest\\Extractor.bat";
if (-f $prog) # does it exist?
{
print "Will run notepad";
system($prog);
}
else
{
print "$prog doesn't exist.";
}
Solution 2
Your code seems a bit confused. What you probably want is something like
my $cmd = "notepad.exe";
my @args = ($cmd, "readme.txt");
system(@args);
if($? == -1) {
die "system @args failed: $?";
}
system
returns a single value, not an array. See perldoc -f system
for a detailed description.
This thread on perlmonks discusses the error you're getting with a few different solutions being presented.
This answer is an extension of my original comment. Sorry if it's superfluous.
Author by
quinekxi
Updated on June 28, 2022Comments
-
quinekxi almost 2 years
How to run an executable file using perl?
For instance, i want to run a plain notepad.exe. How could I achieve this?
This is what I've got:
my @args = system("notepad.exe"); system(@args) == 0 or die "system @args failed: $?";
But it returns:
Can't spawn "cmd.exe": No such file or directory blah blah blah.
What am I missing?
-
quinekxi over 12 yearsThanks you. That's should explains. :)