Linux net command showing incorrect output if executing from java.

Discussion in 'Java' started by mickeyteg, Nov 4, 2010.

  1. mickeyteg

    mickeyteg

    Joined:
    Nov 4, 2010
    Messages:
    1
    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);
    // }
    }
    }

    }
    mickeyteg, Nov 4, 2010
    #1
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. =?Utf-8?B?SW5jb3JyZWN0IGZpbGVuYW1lcyBpbiBkb3dubG9h

    Incorrect filenames are being showing in downloading.

    =?Utf-8?B?SW5jb3JyZWN0IGZpbGVuYW1lcyBpbiBkb3dubG9h, Oct 14, 2005, in forum: ASP .Net
    Replies:
    2
    Views:
    406
    =?Utf-8?B?SW5jb3JyZWN0IGZpbGVuYW1lcyBpbiBkb3dubG9h
    Oct 18, 2005
  2. Sharp Tool
    Replies:
    7
    Views:
    19,580
    Andrew Thompson
    Jul 20, 2005
  3. Mohit Mehral
    Replies:
    3
    Views:
    1,241
    Nigel Wade
    Mar 24, 2006
  4. Fixer
    Replies:
    0
    Views:
    375
    Fixer
    Oct 3, 2007
  5. amarpreetsinghgill
    Replies:
    0
    Views:
    513
    amarpreetsinghgill
    Feb 25, 2008
Loading...

Share This Page