Linux net command showing incorrect output if executing from java.

Joined
Nov 4, 2010
Messages
1
Reaction score
0
Hi I am trying to use net command on linux to check the registry value on windows PC, however the command is throwing "invalid registry path" output although it runs fine when I execute it from linux termial. I am tried using encapsulation the command String in an array, but it didn't help. Please see the code below:

//import java.io.BufferedReader;
//import java.io.IOException;
//import java.io.InputStreamReader;
import java.io.*;

public class ChkBpower {
public static void main(String[] args) {
checkBpower(128);
}


public static void checkBpower (int TTL){
int ttl = TTL;
System.out.println("Hello3");
String ip = "20.198.36.28";
String credentials ="bpwrlab/Administrator%Confmgmt1";//"asiapac/gjagdeosingh%M@nu2281";
String chkBcmd = "net rpc registry enumerate '\\HKEY_LOCAL_MACHINE\\SOFTWARE\\Marimba' -I " + ip + " -U " + credentials ;
String chkBstatus = "net rpc service status cscmarimba -I " + ip + " -U " + credentials + "| grep -b 'service' | awk '{print $4}'";
String startBpower = "net rpc service start cscmarimba -I " + ip + " -U " + credentials;

if (ttl>=100 && ttl<=128){

System.out.println(ttl);
System.out.println(chkBcmd);

try {
Runtime r = Runtime.getRuntime();
Process p = r.exec(chkBcmd);
InputStream stderr = p.getErrorStream();
InputStreamReader isr = new InputStreamReader(stderr);
BufferedReader br = new BufferedReader(isr);
String line = null;
System.out.println("<ERROR>");
System.out.println(br.readLine());
while ( (line = br.readLine()) != null)
System.out.println(line);
System.out.println("</ERROR>");
int exitVal = p.waitFor();
System.out.println("Process exitValue: " + exitVal);
}
catch (Throwable t)
{
t.printStackTrace();
}


//System.out.println("test");
// BufferedReader br = new BufferedReader(new
// InputStreamReader(p.getInputStream()));
// String line;
// System.out.println(br.readLine());

// while ((line = br.readLine()) != null)
// {
// System.out.println(br.readLine());}
// int intline=0;
// if (intline==1){
// Process p2 = r.exec(chkBstatus);
// BufferedReader in2 = new BufferedReader(new
// InputStreamReader(p2.getInputStream()));
// if (in2.readLine()=="stopped."){
// r.exec(startBpower);
// }
// in2.close();
// }
// br.close();
// } //try

// catch (IOException e) {
// System.out.println(e);
// }
}
}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,153
Members
46,699
Latest member
AnneRosen

Latest Threads

Top