2010-06-30 52 views
0

我在大約10年未使用後重新學習Perl。使用Win32 :: Process;我的輸出報告'系統找不到指定的路徑'

我在這個網站上做了一個類似問題的答案之一的下面兩個腳本的複製和粘貼。我已經檢查和雙重檢查的path和試了偏差,但我仍然得到同樣的答案 -

The system cannot find the path specified 

任何幫助將不勝感激!

它確實到達starting child process,並退出並顯示錯誤消息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 '.'; 
} 

回答

2

你需要躲避反斜槓在你的路徑,或使用正斜槓。

看看這個somewhat related post

+0

謝謝,我感謝你的努力,但是這沒有奏效。 我試着C:/Perl/perl.exe C:\\ \\的Perl perl.exe所在 甚至C:\/Perl的\ /perl.exe只是爲了好玩: - } – jpk 2010-07-01 20:51:22

+0

看來你粘貼Unix腳本。我不使用perl,但是我認爲這行在Windows中不起作用:#!/ usr/bin/perl 以下是一些Windows示例: http://forums.devshed.com/perl-programming-6 /problem-with-win32-process-create-360040.html – cdonner 2010-07-02 01:18:33

0

(這個答案將隨着條件的檢查出編輯)

  1. 檢查,有一個c:\Perl directory - (C:\如不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到指定的 窗口路徑#!C:\Perl\perl.exe, 但是,我不認爲這真的很重要,作爲 很多在Windows上,它只是幫助你k現在可執行文件就是這樣的時間。
相關問題