【发布时间】:2017-03-14 01:52:09
【问题描述】:
我可以通过 Powershell 本身运行以下 powershell 命令,
invoke-command -ComputerName "compName" -filepath "c:\script.ps1" -credential "admin"
但是当我尝试通过 Java 运行它时,我得到一个错误。听起来“调用命令”不被识别为通过 Java 运行的程序。如果是这种情况,有没有其他解决办法?
Process p = new ProcessBuilder()
.inheritIO()
.command("invoke-command", "-computername", "compName",
"-filepath", "C:\\script.ps1").start();
错误,
无法运行程序“invoke-command”:CreateProcess error=2,系统找不到指定的文件
附:该错误与提供的文件路径无关,而是与调用命令本身有关。
谢谢。
【问题讨论】:
-
invoke-command不是 Windows 命令,而是 PowerShell 命令,因此您必须通过 PowerShell 命令行运行它,即powershell.exe -Command your-command-here。
标签: java powershell command invoke-command