0

我想通过java执行批处理命令。我怎样才能做到这一点 ?"c:\windows\system32\net use s:\192.168.1.160"\100 Gelem 1" /user:xxx xxx" 这个实际上适用于 windows 命令提示符

我尝试没有成功的代码是:

String[] cmd = { "c:\\windows\\system32\\net","use s: \\\\192.168.1.160\"\\100 Gelem 1     \" /user:100 100"};

Process p = Runtime.getRuntime().exec(cmd);
ProcessBuilder builder = new ProcessBuilder(cmd);
builder.redirectErrorStream(true);
p.waitFor();
4

1 回答 1

0

我终于搞定了!!!

cmd1 = "c:\\windows\\system32\\net.exe " + "use" + " s:" +
                   " \"\\\\192.168.1.160\\100 Gelem 1\"" + " /user:100" + " 100";
String[] cmd = {cmd1};
于 2014-02-12T07:13:28.197 回答