Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: How to see intermediate proceess being executed in linux using java

  1. #1
    Junior Member
    Join Date
    Apr 2010
    Posts
    6
    My Mood
    Aggressive
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default How to see intermediate proceess being executed in linux using java

    Hi All,

    i am running o.s. ubuntu and have posted on 1 forum regarding this but i got partial response to my query.

    i want to see the intermediate and the result in execution of a file in linux. i am doing this by making use of Swing's in java. i have following code to execute:-

    String[] args = {"/bin/sh",
                                  "-c",
                         "/home/nakul/Desktop/srilm/bin/i686/ngram-count -order 2 -text ", s,"-lm Englm.lm -write EngC.count -unk"};
                p1=Runtime.getRuntime().exec(args);
                OutputStream st1=p1.getOutputStream();
                System.out.println(st1);


    i want to see the intermediate results generated by execution of the above mentioned file (ngram-count).

    Kindly tell howto solve this problem.

    Thanks & Regards,


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,318
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: How to see intermediate proceess being executed in linux using java

    Not sure what you mean by 'intermediate', but have a look at the following article: When Runtime.exec() won't - JavaWorld
    It lists how one can go about reading the OutputStream from a Process.

  3. #3
    Junior Member
    Join Date
    Apr 2010
    Posts
    6
    My Mood
    Aggressive
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: How to see intermediate proceess being executed in linux using java

    Hi,

    i mean that whatever intermediates, outputs, files that are generated by this exec(ngram-count), i want it to use it in java's applet.

  4. #4
    Junior Member
    Join Date
    Apr 2010
    Posts
    6
    My Mood
    Aggressive
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: How to see intermediate proceess being executed in linux using java

    Hi,

    i was mistaken the executable is not running and it giving following error while running:-

    /home/nakul/Desktop/srilm/bin/i686/ngram-count: 1: Syntax error: Bad function name

     
     try
            {
                String[] args = {"/bin/sh","/home/nakul/Desktop/srilm/bin/i686/ngram-count","-text", s,"-order","2","-write","EngC.count","-unk"};
                p1=Runtime.getRuntime().exec(args);
     
     
                OutputStream st1=p1.getOutputStream();
                System.out.println( "");
                System.out.println(st1);
                //jTextArea2.append(toString(st1));
                int i=p1.waitFor();
                int j=p1.exitValue();
     
        if(j==0)
        {
            System.out.println("Command Successful");
        }
                if(i == 0)
        {
            System.out.println(i);
     
            jTextArea1.append("\n");
            /*String[] args1 = {"/bin/sh",
                                  "-c",
                         "ls /home/nakul/Desktop/srilm/bin/i686/Englm.lm -al"};
            p2=Runtime.getRuntime().exec(args1);*/
            //jTextArea1.append("Language Model created...");
     
            //p2.wa
            BufferedReader in = new BufferedReader(new InputStreamReader(p1.getInputStream()));
     
            while ((kk = in.readLine()) != null) {
     
               }
            in.close();
        }
     else
        {
    BufferedReader stdErr = new BufferedReader(new InputStreamReader(p1.getErrorStream()));
    // read the output from the command
    while ((s = stdErr.readLine()) != null) {
    System.out.println(s);
    }              
     
     }
     
            }catch(Exception e){
                System.out.println(e);
            }


    So before the executable produce intermediate results first of all it must be running.

    Please tell how to solve this problem....

Similar Threads

  1. Replies: 3
    Last Post: January 28th, 2011, 09:37 AM
  2. How to set java compiler compliance with command under Linux
    By Eric97 in forum Java Theory & Questions
    Replies: 2
    Last Post: November 9th, 2010, 09:25 AM
  3. Help with Linux makefile
    By ruerric in forum What's Wrong With My Code?
    Replies: 1
    Last Post: June 10th, 2010, 10:07 AM
  4. miniBuilder on Linux- java errors
    By nwtjv in forum Exceptions
    Replies: 0
    Last Post: March 25th, 2010, 06:54 AM
  5. Executing Linux Commands with Java GUI
    By linuxrockers in forum AWT / Java Swing
    Replies: 2
    Last Post: February 15th, 2010, 10:57 PM