Question

I try to connect a remote machine using PsExec.exe, and i want to do some work to this machine. Normally i send the request to the remote machine, it works fine but after it finishes,it doesnt return anything but it should be normally. I thought PsExec.exe hangs thats why it couldnt return anything.

here is the java code that i use :

        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);

and the command is :

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() + " -host localhost -port 9999 -threads " + waitingTestSet.getThread() + " -useSingleSession false -tSetId " + waitingTestSet.getTestSetID() + " -u " + availableHost.getuName() + " -p " + availableHost.getuPass() + " -conStr " + connectionString;

Was it helpful?

Solution

Using:

cmd /c c:\PSTools\PsExec.exe

Will cause you to launch a cmd.exe process which in turn launches the PsExec.exe. You may think "Oh, but thats what I want" but its not.

The flag you use with cmd actually does the following:

 /C     Run Command and then terminate

So immediately after the the PsExec.exe process gets launched from the cmd.exe, the cmd.exe process is finished because its only job was to start the PsExec.exe process and terminate. So from the Java standpoint, everything is done.

Just try running the PsExex.exe directly and see if that returns the output you desire.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top