0

经过大约 10 年的不使用,我正在重新学习 Perl。

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

The system cannot find the path specified

任何帮助将不胜感激!

它确实到达starting child process并退出并显示错误消息The system cannot find the path specified

下面是原两个脚本的剪切粘贴

父.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'";

你好.pl

#!/usr/bin/perl

$| = 1;

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

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

2 回答 2

2

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

看看这个有点相关的帖子

于 2010-06-30T02:55:03.100 回答
0

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

  1. 检查是否有c:\Perl directory- 它可能区分大小写(例如C:\not 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 path #!C:\Perl\perl.exe,但是我认为这在 windows 上并不重要,它只是帮助您知道可执行文件在这种情况下的位置。
于 2010-07-03T02:19:12.750 回答