I need to execute a service remotely.To achieve this i run the command PsExec.exe from command prompt.However instead of executing the command manually from the command line i would like to write some java wrapper class that would internally invoke the PsExec.Exe command and fetch the desired result.Kndly help as how do i write such a java class?
In pseudo code:
And since you're going to be using Process, you need to read When Runtime.exec() won't. In this case you get off easy; if you redirect the error stream to the output stream (using the appropriate method from ProcessBuilder) everything will be sent to the same buffer which you are emptying when reading from p.getInputStream().
I see two problems here:
1) you use \\, but that is only one \ in the Java String because \ is the escape character for Strings. To put two backslashes in a Java String you must add 4 in code: "\\10.22.22.33"
2) the ProcessBuilder constructor accepts multiple Strings, but it must have one String per command line argument. In your example PsExec is started with one long argument. Try the following: