Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Java (http://www.velocityreviews.com/forums/f30-java.html)
-   -   Linux net command showing incorrect output if executing from java. (http://www.velocityreviews.com/forums/t737186-linux-net-command-showing-incorrect-output-if-executing-from-java.html)

mickeyteg 11-04-2010 09:39 AM

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

}


All times are GMT. The time now is 07:59 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.