Sys Exec - reading the output

I am using the System Exec.vi to send a command line to the windows command prompt:
"command.com /c w32tm.exe /resync"
I use this to force my PC to update the system time with a time server. When I run this command in the command prompt outside labview I get an output when the process completes that says "The command completed successfully.".
I want to be able to display this message in LabVIEW - however when I wire a string indicator to the "standard output" terminal of the VI I don't get any feedback. Is this possible using this method? Or am I better off reading the return code to establish if the task completed? Return code doesn't seem to do anything either. It would be nice to know whether the process worked or not.
W32tm.exe info:
http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/time_w32tm.mspx?mfr=t...
Message Edited by russelldav on 11-26-2007 02:51 PM
Attachments:
resync.jpg ‏32 KB

I just worked out how to fix this and get the output I wanted...
I changed the command line to:
"w32tm.exe /resync"
and it works fine.  I'm hazarding a guess the /c before was causing the problem?
Does anyone know what the return codes mean? I get "-1073741510" when the program executes.

Similar Messages

  • Read the output of the iseries CL Program from Java

    I have a Java program running on the iseries(AS400). I need to call a CL program from this JAVA.I have to pass 7 arguments to it.Out of 7, three are input parameters to CL and other 4 are its output parameters to the calling JAVA program. I am using Runtime.getRuntime().exec(arguments) to call the CL. Please suggest me how to read the output from the CL in the JAVA program.

    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    Kidding:
    If a method has at least 7 parameters, chances are one or two have been forgotten.

  • How to read the output from 'tlist entersq'

    Hi
    Where can I find information on interpreting the output from 'tlist entersq' ?
    We have a box that seems to go into a lock, no communication through network, nor terminal ttya.
    I did an abort on the panel and sync to force a memory dump
    I'm using scat to investigate the result.
    SolarisCAT(vmcore.0)> thread summary
            reference clock = panic_lbolt: 0x114c6f9                             
       11   threads ran since 1 second before current tick (11 user, 0 kernel)
       11   threads ran since 1 minute before current tick (11 user, 0 kernel)
       63   TS_RUN threads (50 user, 13 kernel)
        2   TS_STOPPED threads (0 user, 2 kernel)
       10   TS_FREE threads (0 user, 10 kernel)
        0   !TS_LOAD (swapped) threads
        0   threads trying to get a mutex
        0   threads trying to get an rwlock
      128   threads waiting for a condition variable (89 user, 39 kernel)
        1   threads sleeping on a semaphore (0 user, 1 kernel)
       12   threads sleeping on a user-level sobj (12 user, 0 kernel)
        7   threads sleeping on a shuttle (door) (7 user, 0 kernel)
        0   threads in biowait()
        1*  threads in entersq() (1 user, 0 kernel)
       63   threads in dispatch queues (50 user, 13 kernel)
      225   total threads in allthreads list (159 user, 66 kernel)
        0   thread_reapcnt
        5   lwp_reapcnt
      230   nthread
    SolarisCAT(vmcore.0)>  tlist entersq
      thread        pri pctcpu           idle   pid         wchan command
      0x300027dd7a0 142  0.024       1m41.83s  1684 0x300007fff18 /sz/tcp/bin/tig_tcp.bin
       1 thread in entersq() found.
    threads in entersq() by syncq:
    1 thread: 0x300027dd7a0
    syncq @ 0x300007ffee0
    sq_count: 0    sq_head: 0x30001de6e80  sq_tail: 0x30001de6e80
    sq_evhead: 0xcff010000 sq_evtail: 0x100000000cafe      sq_nqueues: 0
    sq_needexcl: 0 sq_private: 0x3000155dd18       sq_next: 0xbaddcafe
    sq_pri: 276
    sq_occount: 0
    sq_flags: 0x200 ()
    sq_type:  0x0
    sq_svcflags:  0x0
    sq_lock @ 0x300007ffee0:
      adaptive mutex:  owner: 0x0  waiters: false
    per-module syncq for ip
    streamtab @ 0x14ad6b0
    qinit     @ 0x14ad570
    modinfo   @ 0x14ad540
    queues:1 sq_msgs:1 sq_mblks:36 sq_alloc:13247273932581836904
    SolarisCAT(vmcore.0)> thread 0x30001de6e80
    ==== user thread: 0x30001de6e80 address translation failed for pid: 32 bytes @ 0x452e0d0a2a2a2a20
    pid: 0  PIL: 3 ====
    cmd:
    t_wchan: 0x30001dd5640 
    t_stk: 0x1263bfc  sp: 0x0  t_stkbase: 0x30002aa3ec0
    t_pri: 0  pctcpu: 0.000036  t_lwp: 0x30001de0d80  machpcb: 0x30001dd4c08
    t_procp: 0x30002df2900  p_as: 0x30002df2978  hat: 0x6420373031206368address translation failed for hat_3: 80 bytes @ 0x6420373031206368
      cnum: 0x0
    address translation failed for hat_3: 80 bytes @ 0x6420373031206368
      size: 4984936174853958176  rss: 0
    bound cpuid: 768  bound psrset: 768  last cpuid: 0 
    idle: -17371523 ticks (190888 days 10 hours 34 minutes 34.26 seconds)
    start: Wed Jul 10 21:34:52 6497
    age: -3297429488912 seconds (38164693 days 3 hours 48 minutes 32 seconds)
    swapped out: 3298566244800 (190888 days 4 hours 48 minutes 49.63 seconds later)
    interrupted (pinned) thread: 0x30001de6ef8
    tstate: unknown state
    tflg:   T_INTR_THREAD - thread is an interrupt thread
            T_WOULDBLOCK - for lockfs
            T_DONTBLOCK - for lockfs
            T_DONTPEND - for lockfs
            WAITCVSEM - waiting for a lwp_cv or lwp_sema on sleepq
    tpflg:  TP_CHKPT - thread is being stopped via CPR checkpoint
            TP_PRVSTOP - thread is virtually stopped via /proc
            TP_MSACCT - collect micro-state accounting information
            TP_STOPPING - thread is executing stop()
    tsched: none set
    pflag:  SLOAD - in core
            SLOCK - process cannot be swapped
            SPREXEC - process is in exec() (a flag for /proc)
            SSCONT - SIGCONT has been posted to the process
            SBPTADJ - adjust pc on breakpoint trap (/proc)
            SUGID - process was result of set[ug]id exec
            SJCTL - SIGCLD sent when children stop/continue
            SNOWAIT - children never become zombies
            SVFORK - process resulted from vfork
            SVFWAIT - parent of vfork waiting for child to exec
            EXITLWPS - have lwps exit within the process
            SWAITSIG - SIGWAITING sent when all lwps block
            HOLDFORK1 - hold lwps in place (not cloning)
            SMSACCT - process is keeping micro-state accounting
    pc: 0x30003e63600       0x30003e63600:  illegaltrap     0x00000000
    -- no stack --

    Hello ejp,
    First of all i thank you for the reply.
    I explain the process which i am doing in side the thread.
    After connecting to the remote machine, it asks another password.
    so i read the output after connecting. if it equals "password:", then write the 2nd password. then i read the output. it will be like "system>" . if this prompt comes like this, then i write the super user name and super user password. then the prompt will be like "system#". then i write the command which i need to execute and read the output whether the command is success or not.
    So after every output read, i interrupt the thread using interrupt() method. its working fine if i execute via GUI ie, click the button. But its not working when i scheduled this job in a scheduler ie, it will be executed when the time elapsed.
    Give an idea to fix this bug please.
    rgds
    tskarthikeyan

  • Reading the output from a object running in the local machine.

    Reading the output from a object running in the local machine.
    By using a signed applet i am lunching a small application that returns an image object, how to read that without storing it in the hard disk.
    Which means i need to read the image object return by the local application using applet or jsp .
    i am using tomacat and an html page with an applet with it to lunch the application.

    You can write that image in a binary format using OutputStream for System.out and then read it in your applet.

  • Reading the output values after each step executes in LabVIEW User Interface

    Hello all,
    Development environment: TestStand 2010 SP1 and LabVIEW 2010 SP1
    Problem: is there a way to execute the subsequent steps programatically and get the output values from each of them?
    I have already extended a little bit a Full OI interface for TestStand to load up any sequence, choose some of the steps and run them step by step (something like option to Run Selected steps). What I am trying to do is to add some actions between each step and do that in User Interface (I can't modify the sequence!), so I am starting the NewExecution with some previously configured InteractiveArgsParam and set an option breakAtFirstStep to True. Afterwards I am just doing something like Step Over when debugging the sequence and this works good, but I didn't fine a way yet to read the output values from the steps...
    Then, if I wait until the execution finishes I can read my Results by processing the ResultObject, but this works only after finalizing of the test sequence. Since I wanted to stop after each step, read the values, do some actions and continue to the next step I tried to register an event callback for Trace of Execution View Manager. I can see that after each executed step this event is triggered, but when I try to read a ResultObject returned in Event Data it is not filled with values (ResultList seems to be empty?). Is it a proper behaviour or maybe I am doing the readout in wrong way? (It is the same VI as for reading ResultObjects after sequence finishes and there it works fine for arrays, containers and other data types).
    Like I mentioned I can't modify the Test sequences, I can't add a UImessages.
    What are my options? Should the trace event returns all output values from each steps or is it just used for status checking? Or maybe there is completely different approach to that matter?
    Thanks in advance for any suggestions,
    Best Regards.
    CLA, CTD, CLED @ Test & Measurements Solutions Poland
    Solved!
    Go to Solution.

    Thanks for your replay, I have tried to build it in my LabView Block Diagramm, es seems like this image.
    But the variable GetNumSubProperties ist always 0. Why?
    PS: I need only the variable "Step.Result.PassFail" from the last step, do you know, how can I get it? I think, it is maybe easier than read all the "Result".
    Attachments:
    ReadStepResultInLabview.JPG ‏39 KB

  • Reading the output from another program.

    I haven't used Java in a good long while so I need someone to point me in the right direction. I have a C program that I call from a command line (windoze boxen) and it spits out some neat data. I can call it from inside a Java program, but how do I then read the output from the calling Java program? I'd just alter the C program, but I lost the source.

    This article explains how to correctly execute another program from your
    Java program, and read its output:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

  • Reading The Output From A POST To A Webserver

    Any suggestions on the following would be greatly appreciated!! From all examples, what I'm doing is correct, but I can't get the results of the Post.
    I am trying to do the following:
    1. Connect to a webserver through a URL object.
    2. POST a user name and password to a login screen.
    3. Read the Data Page that comes after login.
    I have successfully done item 1, but am failing at either item 2 or 3.
    I have read the forum extensively on Posting to webservers and have followed many examples. However my application does not get past the login screen. My application does not error, but the html that I read is the html of the Login Screen and not the html of the Data Page.
    Here's my code:
    import java.awt.*;
    import java.awt.event.*;
    import java.net.*;
    import java.io.*;
         public class HttpPostReader3 {
         StringBuffer lineBuff;
         public HttpPostReader3() {
    lineBuff = new StringBuffer();
    URL url;
    HttpURLConnection connection=null;
    String queryparam = "https://a_website/login.asp";
    try
    // Get URL
    url = new URL(queryparam);
    // Get a HttpURLConnection Object
    connection = (HttpURLConnection)url.openConnection();
    // prepare for both input and output
    connection.setDoOutput(true);
    // set request to post
    connection.setRequestMethod("POST");
    // Encode the URL POST String and assemble it
    String postparameter = URLEncoder.encode("txtUserID") + "=" + URLEncoder.encode("a_user_id");
    postparameter += "&" + URLEncoder.encode("txtPassword") + "=" + URLEncoder.encode("a_password");
    postparameter += "&" + URLEncoder.encode("chkAutoLogin") + "=" + URLEncoder.encode("Y");
    postparameter += "&" + URLEncoder.encode("Login") + "=" + URLEncoder.encode("Login");
    // Create a outstream for posting the parameters and set the outstream to ASCII data
    OutputStreamWriter outStream = new OutputStreamWriter(new BufferedOutputStream(connection.getOutputStream()),"ASCII");
    outStream.write(postparameter); // POST occurs here for name value pairs
    outStream.close();
    // get output streams of connection
    BufferedReader in = new BufferedReader( new InputStreamReader( connection.getInputStream()));
    String inputLine;
    while ((inputLine = in.readLine()) != null)
         System.out.println(inputLine);
         lineBuff.append( "\n" );
         lineBuff.append( inputLine );
    catch(IOException e)
    System.out.println(e);
    //WRITE OUTPUT HTML TO A TEXT FILE CALLED UNTITLED.TXT
                   String htmlFile;
                   htmlFile = lineBuff.toString();
              // Read and append data to a text file
              try{
              String fileName = "untitled.txt"; // Filename
              // Make the inputfile object
              FileInputStream fi = new FileInputStream(fileName);
              byte inData[] = new byte[fi.available()];
              fi.read(inData); // Read
              fi.close(); // Close
              String text = new String(inData); // Make a textstring...
              // Now, do whatever you want with the data... and append...
              String textToAppend = "xyzzzz";
              //byte outData[] = textToAppend.getBytes();
              byte outData[] = htmlFile.getBytes();
              // Make the outputfile (whith the 'append' boolean set to true
              FileOutputStream fo = new FileOutputStream(fileName,true);
              fo.write(outData);
              fo.close();
              }catch(Exception oops){
                   System.out.println("error with untitled.txt");
                   finally
                             System.exit(0);
              public static void main(String[] args)
                                  HttpPostReader3 h = new HttpPostReader3();//constructor
    } //End HTTPPostReader3

    You are very wise, but I have thought of that. Login.asp creates an html page that has a <form> statement with a submit action (Post) to login.asp. I pulled this out of the html.
    I did get lucky and found that for a bad login, the asp replies with "Bad Login". Since I know the login, I tried both the good login and a bad login. I found that I am posting correctly and logging in (at least my login is recognized as good and bad as bad).
    However, I don't get the information of the next page (the next page does come from default.asp)!
    WHAT DO I KNOW:
    1. I am posting correctly.
    2. My login was recognized as good.
    3. I don't get the next page, which comes from default.asp. Note, you can't go to default.asp directly, it will send you back to login.asp.

  • Cannot read the output from windows command.

    Hello
    I have the following classes
    package cmd;
    import java.io.IOException;
    public class CMD {
        public CMD(){
            ProcessBuilder pb = new ProcessBuilder()
            .command("cmd.exe","/c","del *.*")
            .redirectErrorStream(false);
            Process p;
            try {
                p = pb.start();
                StreamGobbler errorGobbler = new StreamGobbler(p.getErrorStream(), "ERROR");
                // any output?
                StreamGobbler outputGobbler = new StreamGobbler(p.getInputStream(), "OUTPUT");
                // start gobblers
                outputGobbler.start();
                errorGobbler.start();
            } catch (IOException e) {
                // TODO Auto-generated catch block
            System.out.println("eee "+e.getMessage());;
        public static void main(String[] args) {
            System.out.println("x");
            new CMD();
            System.out.println("x");
    and
    package cmd;
    import java.io.BufferedReader;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.InputStreamReader;
    public class StreamGobbler extends Thread {
        InputStream is;
        String type;
        StreamGobbler(InputStream is, String type) {
            this.is = is;
            this.type = type;
        @Override
        public void run() {
            try {
                InputStreamReader isr = new InputStreamReader(is);
                BufferedReader br = new BufferedReader(isr);
                String line = null;
                while ((line = br.readLine()) != null)
                    System.out.println(type + "> " + line);
            catch (IOException ioe) {
                ioe.printStackTrace();
    Please note that I cannot seee the output from wndows command : del *.* and the java class execution does not finished.
    I I will replace the above command with the dir command then the output of the command is visible.
    Would you give me a hint about how to modify the above clases in order to parse the output of the del *.* ?
    Please note that the above example is important because I am developping a tool and it is mandatory for that tool to parse the output from a windows batch command.
    Best regards,

    Please note that I cannot seee the output from wndows command : del *.* and the java class execution does not finished.
    I I will replace the above command with the dir command then the output of the command is visible.
    Would you give me a hint about how to modify the above clases in order to parse the output of the del *.* ?
    No - but I will give you a hint about ProcessBuilder and how to develop software properly.
    Hint #1: Don't try to automate something that you don't know, or understand, how to do manually.
    a. Do you know how to execute 'del *.*' manually in a command window?
    b. Did you try that manually to see what happens?
    My guess is 'no'. If you had you would know that the response to a 'del *.*' command is going to be this:
    Are you sure (Y/N)?
    And your 'java class execution' doesn't finish because the 'del' command is waiting for you to answer that question.
    Hint #2: Don't try to use ProcessBuilder for an application that requires console input unless you first know how to provide that console input via your Java code.
    Your code will wait forever since it does NOT answer that question.
    Search the net and The Java Tutorials and  you can find examples of executing command line utilities. Then try those examples first and make sure that:
    1. They work for you
    2. You understand HOW they work
    Then you can modify those examples to do what you want to do.

  • Read the output of a jsp into a string

    I need a servlet that can return the output html of a jsp as a string. How can I do this? I played around with constructing a URL object and getting an InputStream from that but without success.

    This is kind of a weird hack, but it just might work. If it's only one jsp file that you're working with, instead of putting the code inside a jsp, put it in a servlet instead. Wherever you're outputting something call the method below:
    private String totalOutput="";
    private void doubleOutput(PrintWriter jspout, PrintWriter fileout, String mytext){
       jspout.println(mytext);
       fileout.println(mytext);
       totalOutput+=mytext;
    }So basically you would get the jspout from the response.getWriter() method (in either doGet or doPost method). The fileout is basically a PrintWriter associated with a new FileOutputStream(tempfilename).
    Now, you basically have all the output you need in the file and you can access it later. Alternatively, at the end of the servlet's doGet or doPost method, you'll have access to everything that's output in that 'totalOutput' String (don't forget to reset it after every call to doGet/doPost!)

  • How to read the output of 'tarantella license query' command?

    I'm trying to track my license usage (to better determine when to buy new licenses, and to track usage over time).
    When I issue the 'tarantella license query command, this is typical of the output I see:
    [root@sgdserver ~]# /opt/tarantella/bin/tarantella license query
    License usage at: Mon Feb 11 14:03:53 EST 2008
    Type                In use / Total
    Base                6      / 230
    UNIX                4      / 230
    Mainframe           0      / 230
    Windows             0      / 230
    AS/400              0      / 230
    [root@sgdserver ~]#What is the above saying? Is it saying that I am using 10 licenses out of my 230, or am I just using 6 licenses? In other words, do I add up the numbers or just use the highest one? Or do I just have to worry about the 'Base' license number?
    Thanks.

    The base license is the number of users that are logged into a webtop.
    From there you count then connectivity type.
    So you have 6 webtop licenses out of 230 consumed and of those 4 users have launched UNIX sessions out of 230 you have licensed.
    hope this helps.

  • Java Runtime.exec - can you read the output interactively?

    I am running a program never ends, its a text based download manager. It gives output on ONE line, and this isnt in std.out (im using unix).
    this continues (basically it just gives you a view of how much progress the file is downloading.
    Is there a way to read this from java?
    cheers.

    try
    {   // Execute command
        String command = "aCommand";
        Process child =  Runtime.getRuntime().exec (command);
        // Get input stream to read from it
        InputStream in = child.getInputStream();
        int c;
        System.out.println("Command returns ");
        while ((c = in.read()) != -1)
            System.out.println("---"+((char)c));
        in.close();
    catch (IOException e)
         System.out.println("Exception occurred: "+e);
    }

  • What is the difference between LV general and LV RT if we consider I want to read the output of a temperature sensor online??

    Hi everybody,
    I am very new in LV and I need to read my temperature sensore outputs online in order to make needed changes to the system each time that the temperature changes. If I use LV genral or LV RT??
    Thanks
    Solved!
    Go to Solution.

    Hi elahetal.  The LV vs. LV RT decision really depends on what your timing requirements are.
    RT isn't necessarily about being as fast as possible, but rather as consistent as possible.
    If you have a measurement that must be taken every 100mS +/- 2mS then you pretty much have to use RT.  A general purpose OS like Windows will randomly go off and do other things (read a cd, feed the printer, index the disk, etc.), causing your measurement to be late.
    An RT environment will allow you to determine precisely when the system should do what.  The trade-off is that the RT environment is somewhat restricted, in that you don't have all the bells and whistles of a gp OS.
    If your measurement must be taken every 15S +/- 10S then you may very well get away with standard LV on a PC.
    In some instances, a combination works well.  For example, RT on FieldPoint or CRIO to handle the time sensitive issues and LV on a PC to handle the user interface and data analysis.
    Hope that helps, please elaborate on your requirements if you wish.
    Matt

  • Shall I use NRSE or RSE mode for reading the output voltage of my sensor?

    Hello,
    I am using a  gaz sensor that needs a power supply of 24 V and has an output voltage  : 0 -> 10 V. I want to read this voltage with labview( and then convert it to PPMs ).
    My problem : I don't know what kind of analog input connection I must use : RSE ou NRSE ? ( I suppose the DIFF mode isn't appriopriate here ) .
    I think I should use the NRSE mode ( meaning connecting the V+ of the 0-10V signal to one of the ACH and the V- to  AISENSE )  ???
    Any help would be really great,
    Regards,
    David     
    PS : using Labview 7.1

    Hi David,
    It basically all boils down to if the signal source is grounded or floating? If grounded use DIFF for low voltages (0-2V) and NRSE for high (above 2V). If the signal is floating use RSE.
    For more documentation see:
    http://digital.ni.com/public.nsf/websearch/D509679FFAE2764386256297005D0C9D
    http://zone.ni.com/devzone/conceptd.nsf/webmain/177A8B29FEDC0F5886256FA90083C0F8
    Regards
    Meister, NIDK

  • Runtime.getRuntime().exec hangs and doesn't print the output

    Hi,
    I have written the following code to execute the command "psexec ipaddress -u userid -p password -l -c execute.exe >> c:/25_showoutpout.txt" and print the output in 25_showoutpout.txt file.
    import java.io.*;
    public class ExecTest{
         public static void main(String args[]) throws IOException{
         String args1 = "psexec ipaddress -u userid -p password -l -c execute.exe >> c:/25_showoutpout.txt";
         try{
         Process p=Runtime.getRuntime().exec(args1);
    int i = p.waitFor();
         System.out.println("Done.with time "+i);
         }catch(Exception e){
              System.out.println("The error is "+e);
    But this program hangs and creates a blank 25_showoutpout.txt file.In the process list I can see the process running, but it doesn't redirect the output in the txt file.When i run the command from the command line it runs fine.Please help me.
    Thanks in advance

    Hi,
    I have written the following program to get the output.But still the required output is not coming in the console file.Only the messages that gets printed in the parent console that is coming in the file.But the expected output is to get the messages from the child window which gets executed while the .exe runs.
    import java.io.*;
    public class RuntimeExecTest{
    public static void main(String args[]){
    String s = null;
    String result= null;
    int count =0;
    try{
              // read the output from the command
    String cmd = "cmd.exe /c D:/installer/PsTools.zip/PsTools/psexec.exe ipaddress -u userid -p password -l -c excute.exe >> C:/RuntimeExec_25.txt";
         Process p = Runtime.getRuntime().exec(cmd);
         InputStream is = p.getInputStream();
         // Get the std in to the process.
         OutputStream os = p.getOutputStream();
         // Get the std err from the process.
         InputStream es = p.getErrorStream();
         // Create readers for those streams.
         BufferedReader reader = new BufferedReader(new InputStreamReader(is));
         BufferedReader errReader = new BufferedReader(new InputStreamReader(es));
         String line;               
         // Read STDOUT into a buffer.
         // If no STDOUT check STDERR.
         while((line = errReader.readLine()) != null){
              // Do something with data here if you wish.
         System.out.println( line );
         while((line = reader.readLine()) != null){
              // Do something with data here if you wish.
         System.out.println( line );
         System.exit(0);
    catch( Exception ex )
    ex.printStackTrace();
    }

  • How to get the output of my batch file or script file

    Hello,
    I am a beginner in java and I have to run a batch file(in win) or a script(in linux). I want the output of the file in my java program. How to read the output. I used the following code and it always gave me the empty string output
    Runtime r = Runtime.getRuntime();
    Process p = null;
    p = r.exec("./test.bat"); //./test.sh
    int res = p.waitFor();
    BufferedReader br = new BufferedReader(new InputStreamReader(p.getInputStream()));
    String tempStr = "", str = null;
    while((str=br.readLine()) != null) {
    tempStr += str + "\n";
    System.out.println(tempStr);
    I know this is a simple one but it's taking a lot of time. Can any one there help me quickly.

    hi
    the below function works well for me..
    just make a try with it
    protected String runConsoleCommand(String command) throws IOException {
    Process p = Runtime.getRuntime().exec(command);
    InputStream stdoutStream = new BufferedInputStream(p.getInputStream());
    StringBuffer buffer = new StringBuffer();
    for (; ; ) {
    int c = stdoutStream.read();
    if (c == -1)
    break;
    buffer.append( (char) c);
    String outputText = buffer.toString();
    stdoutStream.close();
    System.out.println("the output to file is:"+outputText);
    return outputText;

Maybe you are looking for