private static final int TIME_OUT = 2000;
private final static String ip = "192.168.70.147";
private final static String username = "Administrator";
private final static String passwd = "Yanfa_1304";
private final static String command = "c:\test.bat";
public static void main(String[] args) throws IOException, InterruptedException {
Process p;
String cmd = "c:\\psexec \\" + ip + " -u " + username + " -p " + passwd + " -s " + command;
//执行命令
p = Runtime.getRuntime().exec(cmd);
p.waitFor(TIME_OUT, TimeUnit.MILLISECONDS);
BufferedReader errReader =
new BufferedReader(new InputStreamReader(p.getErrorStream(), "GBK"));
String errString = errReader.readLine();
if (!StringUtils.isEmpty(errString)) {
System.out.println("fail");
} else {
System.out.println("success");
}
}