我尝试使用 PsExec.exe 连接远程计算机,我想为此计算机做一些工作。 通常我将请求发送到远程机器,它工作正常,但它完成后,它不返回任何东西,但它应该是正常的。我认为 PsExec.exe 会挂起这就是为什么它无法返回任何内容。
这是我使用的java代码:
Process p = Runtime.getRuntime().exec(command);
InputStream stderr = p.getErrorStream();
InputStreamReader isr = new InputStreamReader(stderr);
BufferedReader br = new BufferedReader(isr);
String line = null;
while ((line = br.readLine()) != null)
System.out.println(line);
int exitVal = p.waitFor();
System.out.println("Process exitValue: " + exitVal);
,命令是:
String command =“cmd / c c:\ PSTools \ PsExec.exe \\”+ availableHost.getHostName() +“java -cp c:\ sahi \ lib \ ant-sahi.jar net.sf.sahi.test.TestRunner -test”+ waitingTestSet.getPath()+“-browserType” + waitingTestSet.getBrowserType()+“ - baseURL”+ waitingTestSet.getUrl()+“ - local localhost -port 9999 -threads” + waitingTestSet.getThread()+“ - useSingleSession false -tSetId”+ waitingTestSet.getTestSetID()+“ - u” + availableHost.getuName()+“ - p”+ availableHost.getuPass()+“ - conStr”+ connectionString;
答案 0 :(得分:2)
使用:
cmd /c c:\PSTools\PsExec.exe
将导致您启动cmd.exe
进程,然后启动PsExec.exe
。你可能会想“哦,但这就是我想要的东西”但不是。
您与cmd
一起使用的旗帜实际上会执行以下操作:
/C Run Command and then terminate
因此PsExec.exe
进程从cmd.exe
启动后立即完成cmd.exe
进程,因为它唯一的工作是启动PsExec.exe
进程并终止。所以从Java的角度来看,一切都已完成。
只需尝试直接运行PsExex.exe
,看看是否会返回您想要的输出。