JAVA中的命令提示符
我必须通过CMD命令使用管理员previlege打开CMD。因此,我尝试了这段代码,然后它要求输入密码,但如何在相同的过程中提供密码呢。然后,我必须抓住新打开的CMDJAVA中的命令提示符,java,command-prompt,Java,Command Prompt,我必须通过CMD命令使用管理员previlege打开CMD。因此,我尝试了这段代码,然后它要求输入密码,但如何在相同的过程中提供密码呢。然后,我必须抓住新打开的CMD Process p = Runtime.getRuntime().exec("runas /noprofile /user:Partha >fg.txt") p.waitFor(); p=Runtime.getRuntime().exec("password"); p.waitFor(); 您最好使用允许将密码作为参数传递
Process p = Runtime.getRuntime().exec("runas /noprofile /user:Partha >fg.txt")
p.waitFor();
p=Runtime.getRuntime().exec("password");
p.waitFor();
您最好使用允许将密码作为参数传递的util:
psexec \\computername -u domain\user -p password
否则,您可以尝试将密码作为STDIN传递:
Runtime.getRuntime().exec("cmd /C echo YOUR_PASS | runas /noprofile /user:Partha >fg.txt");
您最好使用允许将密码作为参数传递的util:
psexec \\computername -u domain\user -p password
否则,您可以尝试将密码作为STDIN传递:
Runtime.getRuntime().exec("cmd /C echo YOUR_PASS | runas /noprofile /user:Partha >fg.txt");
除了@aleroot的答案,您应该使用ProcessBuilder而不是Runtime.exec除了@aleroot的答案,您应该使用ProcessBuilder而不是Runtime.exec请在问题中以文本形式发布代码,不要将其作为图像附加。请在问题中以文本形式发布代码,不要将其作为图像附加。