![](/img/trans.png)
[英]“Cannot run program” when using Runtime.exec with spaces in program filename
[英]“Cannot run program” when using Runtime.exec with spaces in command
cmd=powershell.exe;$passwd=convertto-securestring -AsPlainText -Force -String abc;$cred=new-object -typename System.Management.Automation.PSCredential -argumentlist "xyz",$passwd;$session=new-PSSession -Computer mobilesaucelabs.westeurope.cloudapp.azure.com -Credential $cred -UseSSL;Invoke-Command -Session $session -FilePath C:\\FetchMfilesVersion.ps1
Process process = Runtime.getRuntime().exec(cmd);
由于空格,它会引发错误。
有人可以让我知道如何使用java运行上述命令。
提前致谢!
尝试这个:
string[] cmd = {"powershell.exe;$passwd=convertto-securestring", "-AsPlainText", "-Force", "-String", "abc;$cred=new-object", "-typename", "System.Management.Automation.PSCredential", "-argumentlist 'xyz'","$passwd;$session=new-PSSession", "-Computer", "mobilesaucelabs.westeurope.cloudapp.azure.com", "-Credential", "$cred", "-UseSSL;Invoke-Command", "-Session", "$session", "AddCodeWithSpacesSoOn"};
Process process = Runtime.getRuntime().exec(cmd);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.