我怎么可以这样写PowerShell命令在perl脚本

问题描述:

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

我相信在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

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 }"}