简体   繁体   English

在命令中使用带有空格的 Runtime.exec 时“无法运行程序”

[英]“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 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);

It throws error because of spaces.由于空格,它会引发错误。

Could someone please let me know how to run the above command using java.有人可以让我知道如何使用java运行上述命令。

Thanks in advance!提前致谢!

Try this:尝试这个:

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM