2017-06-19 55 views
-3
invoke-command HOST01 { cmd /C dir /S /B D:\file1 } 

我怎麼能包括在Perl腳本命令我嘗試使用我怎麼可以這樣寫PowerShell命令在perl腳本

qx(invoke-command HOST01 { cmd /C dir /S /B D:\file1 })它不工作,該程序將永遠運行下去。

+0

參見:https://stackoverflow.com/questions/2770124/executing- powershell-from-perl?rq = 1 – lit

回答

-1

我相信在Perl中運行一個外部程序已經被問及過很多次了。

my @output = qx(powershell -NoProfile -Command "icm HOST01 { gci -n -rec D:\\file1 }"); 

foreach my $line (@output) { 
    print $line; 
} 

my $output = qx(powershell -NoProfile -Command "icm HOST01 { gci -n -rec D:\\file1 }"); 

print $output; 
+0

'foreach my $ line($ output){print $ line; }'更好地寫成'print $ output;' – mob

+0

這與我在問題中提到的命令相同,我專門告訴它不工作,這是我得到的輸出,cmdlet的名稱及其模塊名稱 – PopCorn

+0

請編輯包括代碼和輸出的問題。在評論中這是不可能的。 – lit

0

invoke-command HOST01 { cmd /C dir /S /B D:\file1 }不是殼(cmd)命令。這是一個PowerShell命令,因此您需要從調用PowerShell開始。

這是你在命令行中運行的內容:

PowerShell -NoProfile -Command "Invoke-Command HOST01 { cmd /C dir /S /B D:\file1 }" 

所以,你想:

qx{PowerShell -NoProfile -Command "Invoke-Command HOST01 { cmd /C dir /S /B D:\file1 }"} 
相關問題