使用 Win32::进程;我的输出报告“系统找不到指定的路径”

发布于 2024-09-07 18:31:58 字数 972 浏览 1 评论 0原文

在大约 10 年没有使用 Perl 后,我正在重新学习 Perl。

我从本网站上类似问题的答案之一复制并粘贴了以下两个脚本。我已经检查并仔细检查了路径并尝试了几种偏差,但我仍然得到相同的答案 -

The system cannot find the path specified

任何帮助将不胜感激!

它确实到达正在启动的子进程,并退出并显示错误消息系统找不到指定的路径

下面是原始两个脚本parent.pl的剪切和粘贴

#!/usr/bin/perl


use warnings;

use Win32;
use Win32::Process;

$| = 1;

my $p;

print "Starting child process ... \n";

Win32::Process::Create(
    $p,
    'c:\Perl\perl.exe',
    'perl hello.pl',
    1,
    NORMAL_PRIORITY_CLASS,
    '.',
) or die Win32::FormatMessage( Win32::GetLastError() );

print "Waiting three seconds before killing 'hello.pl'\n";

for (1 .. 3) {
    print;
    sleep 1;
}
$p->Kill(0)
    or die "Cannot kill '$p'";

hello.pl

#!/usr/bin/perl

$| = 1;

print "Hello World\n";
print "Sleeping 1000 seconds\n";

for (1 .. 1000) {
    sleep 1;
    print '.';
}

I am relearning Perl after about 10 years of non use.

I did a copy and paste of the two scripts below from one of the answers for a similar question on this site. I have checked and double checked the path and tried several deviations, but I still get the same answer -

The system cannot find the path specified

Any help would be greatly appreciated!

It does get to the starting child process and the exits with the error message The system cannot find the path specified.

Below is the cut and paste of the original two scripts

parent.pl:

#!/usr/bin/perl


use warnings;

use Win32;
use Win32::Process;

$| = 1;

my $p;

print "Starting child process ... \n";

Win32::Process::Create(
    $p,
    'c:\Perl\perl.exe',
    'perl hello.pl',
    1,
    NORMAL_PRIORITY_CLASS,
    '.',
) or die Win32::FormatMessage( Win32::GetLastError() );

print "Waiting three seconds before killing 'hello.pl'\n";

for (1 .. 3) {
    print;
    sleep 1;
}
$p->Kill(0)
    or die "Cannot kill '$p'";

hello.pl

#!/usr/bin/perl

$| = 1;

print "Hello World\n";
print "Sleeping 1000 seconds\n";

for (1 .. 1000) {
    sleep 1;
    print '.';
}

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

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

发布评论

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

评论(2

秋风の叶未落 2024-09-14 18:31:58

您需要转义路径中的反斜杠,或使用正斜杠。

看看这个有点相关的帖子

You need to escape the backslashes in your path, or use forward slashes.

Look at this somewhat related post.

手心的温暖 2024-09-14 18:31:58

(此答案将在条件检查时进行编辑)

  1. 检查是否有 c:\Perl 目录 - 它可能区分大小写(例如 C:\ 不是 < code>c:\)
  2. 确保该目录中列出了 perl.exe,实际路径可能是 C:\Perl\bin\perl.exe
  3. 'perl hello.pl' 可能需要是完全限定的 perl 路径(例如
    'C:\Perl\perl.exe hello.pl'
    )

旁注:

  1. 由于您使用的是单引号 ('),因此您不需要转义反斜杠 (\)
  2. 如果处理
    在 Windows 上您可以更改:
    #!/usr/bin/perl 到指定的
    Windows 路径 #!C:\Perl\perl.exe
    但我认为这并不重要,因为
    在 Windows 上,它只是帮助您在这种情况下知道可执行文件在哪里。

(This answer will be edited as conditions check out)

  1. check that there is a c:\Perl directory - it may be case-sensitive (eg. C:\ not c:\)
  2. make sure there's a perl.exe listed in that directory, the actual path might be C:\Perl\bin\perl.exe
  3. 'perl hello.pl' may need to be the full qualified perl path (eg
    'C:\Perl\perl.exe hello.pl'
    )

Side Note:

  1. Since you're using single-quotes (') you shouldn't need to escape your backslash (\)
  2. If processing
    on windows you may change:
    #!/usr/bin/perl to the specified
    windows path #!C:\Perl\perl.exe ,
    however I don't think this really matters as
    much on windows, it just helps you know where the executable is for times like this.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文