我怎么可以这样写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 })
它不工作,该程序将永远运行下去。
答
我相信在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;
答
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 }"}
参见:https://stackoverflow.com/questions/2770124/executing- powershell-from-perl?rq = 1 – lit