gpt4 book ai didi

java - 将Runtime.exec与命令中的空格一起使用时的“Cannot run program”

转载 作者:行者123 更新时间:2023-12-03 00:06:34 25 4
gpt4 key购买 nike

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com