Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
JAVA中的命令提示符_Java_Command Prompt - Fatal编程技术网

JAVA中的命令提示符

JAVA中的命令提示符,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(); 您最好使用允许将密码作为参数传递

我必须通过CMD命令使用管理员previlege打开CMD。因此,我尝试了这段代码,然后它要求输入密码,但如何在相同的过程中提供密码呢。然后,我必须抓住新打开的CMD

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

请在问题中以文本形式发布代码,不要将其作为图像附加。请在问题中以文本形式发布代码,不要将其作为图像附加。