I want to run a powershell in some remote machine using java. How can this be achieved.? currently this code is not running the powershell command locally.!!
public void main() throws Exception{
String[] command = { /*"cmd.exe", "/C",*/ "powershell", "Command","&","echo '********** hello world ********'"};
String out;
ProcessBuilder processBuilder = new ProcessBuilder(command);
Process process = null;
try {
process = processBuilder.start();
Logger.getInstance().info("process started" );
} catch (IOException e2) {
// TODO Auto-generated catch block
e2.printStackTrace();
}
java.io.InputStream is = process.getInputStream();
InputStreamReader isr = new InputStreamReader(is);
BufferedReader br = new BufferedReader(isr);
// create a reader for the return data from cmd.
StringBuilder sb = new StringBuilder();
// create a string builder to automate the string addition
try {
while ((out = br.readLine()) != null) {// build the input
// string from
// cmd.
sb = sb.append(out);
System.out.println(out);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
this code runs for indefinite time. without any output.