如何在 Windows XP 上使用 Perl 运行可执行文件?

发布于 2024-12-17 09:54:06 字数 316 浏览 0 评论 0原文

如何使用perl运行可执行文件?

例如,我想运行一个普通的 notepad.exe。我怎样才能做到这一点?

这就是我所得到的:

my @args = system("notepad.exe");
system(@args) == 0  or die "system @args failed: $?";

但它返回:

Can't spawn "cmd.exe": No such file or directory blah blah blah.

我缺少什么?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

柠檬色的秋千 2024-12-24 09:54:06

你的代码看起来有点混乱。您可能想要的是类似

my $cmd = "notepad.exe";
my @args = ($cmd, "readme.txt");

system(@args);

if($? == -1) {
    die "system @args failed: $?";
}

system 返回单个值,而不是数组。有关详细说明,请参阅 perldoc -f system

perlmonks 上的这个帖子讨论了您在提供一些不同解决方案时遇到的错误。

这个答案是我原来的评论的延伸。抱歉,如果这是多余的。

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.

维持三分热 2024-12-24 09:54:06

试试这个。

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

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.";
}
简单 2024-12-24 09:54:06

这是 Perl 内部错误,可能是由损坏的环境引起的。 Perl 找不到 Windows shell cmd.exe,该 shell 在幕后用于运行传递给 system 的程序。

使用进程监视器等实用程序来查看操作系统级别发生的情况。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文