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);
关于java - 将Runtime.exec与命令中的空格一起使用时的“Cannot run program”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60162328/