How to run an executable file using Perl on Windows XP?

匆匆过客 提交于 2019-12-02 00:59:00

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.";
}

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.

This is a Perl internal error probably caused by a broken environment. Perl can't find the Windows shell cmd.exe that is used under the hood to run the program passed to system.

Use some utility as Process Monitor to see what's going on at the OS level.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!