使用 Win32::进程;我的输出报告“系统找不到指定的路径”
在大约 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您需要转义路径中的反斜杠,或使用正斜杠。
看看这个有点相关的帖子。
You need to escape the backslashes in your path, or use forward slashes.
Look at this somewhat related post.
(此答案将在条件检查时进行编辑)
c:\Perl 目录
- 它可能区分大小写(例如C:\
不是 < code>c:\)perl.exe
,实际路径可能是C:\Perl\bin\perl.exe
'perl hello.pl'
可能需要是完全限定的 perl 路径(例如
)'C:\Perl\perl.exe hello.pl'
旁注:
'
),因此您不需要转义反斜杠 (\
)在 Windows 上您可以更改:
#!/usr/bin/perl
到指定的Windows 路径
#!C:\Perl\perl.exe
,但我认为这并不重要,因为
在 Windows 上,它只是帮助您在这种情况下知道可执行文件在哪里。
(This answer will be edited as conditions check out)
c:\Perl directory
- it may be case-sensitive (eg.C:\
notc:\
)perl.exe
listed in that directory, the actual path might beC:\Perl\bin\perl.exe
'perl hello.pl'
may need to be the full qualified perl path (eg
)'C:\Perl\perl.exe hello.pl'
Side Note:
'
) you shouldn't need to escape your backslash (\
)on windows you may change:
#!/usr/bin/perl
to the specifiedwindows 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.