Running programs and grabbing their output

I'm kinda confused. I want to run command.com from java and be able to capture its output and print it somewhere else, as well as insert my own input through another medium (ie. JTextField). I know i can use runtime to execute it, and then use process to get the output stream and input stream, but when i get the output stream, it returns it as an output stream, which would mean i couldnt actually read what the program was outputting, i could only write to it, which doesnt make sense at all. Will somebody please explain to me what i'm doing wrong, or if i dont have it wrong, please explain to me how to do what i want to do.
Thank you

The above posts seem to be right:
// Get the runtime. Replace 'this' with what you want from
Runtime rt = this.getRuntime();
// Intialize a variable for recieving the output
byte b[] = new byte[10000];
// Get a stream to recieve the output
InputStream outputOfRT = rt.getRuntime();
// Read the output. Use a better read() logic to all the stuff
read(b);
// Manipulate the b for what you want
rajesh

Similar Messages

  • How to run different programs and use their output in other programs

    Dear java members,
    I am trying to figure out how to get data from a file, database, or program and use that information in another
    program. Can you help please?
    I have looked through several texts and while the information is there somewhere I have not found the specific
    capabilities or examples that explain how to do this.
    I want to learn how to do this with objects.
    The specific applications I am working with are the GIS (Geographic Information System) suite of ESRI products
    such as ArcInfo and ArcView.
    I am working with simulators for hydrologeology (ground water) and other geophysical phenomenae. Programs for
    decisions and assessment of probability such as found in geostatistical analyses packages. Drawing programs
    and data manipulation programs such as spreadsheets in windows and scripting languages found in most Unix
    packages.
    I want to be proprietary platform free! I want to be accessing apps and or data wherever they are and in
    whichever form they are in or best used.
    Web techniques and protocols are where I think most of my effort will be focused.
    One of the mediums (media) that I expect to use a lot is XML.
    If I can find a simplified (generalized) explanation how this is done and how the parts fit together through and or
    with objects. If I can find references to texts and examples I will be very appreciative and very much less
    confused.
    I am interested in using the Java programming language.
    Thank you
    ctavares1

    Hello ctavares1,
    I am not quite sure that I understand what you are trying to do. The programs that you mention: ArcInfo and ArcView, are they stand alone, native, platform dependent applications? Or are they written in Java? It sounds like there are stand alone, native, platform dependent applications, that write their output to either a file or a database.
    The other piece that is puzzling me is: Do you intend to write an Applet or a Java Application? This is important because Java places several restrictions on what an Applet can do.
    There is also the question of how the data is produced. Is it produced all at once in batch or is it produced a little at a time in real time?
    These and other questions will need to be answered before you can begin designing your application. There are many tutorials dealing with opening a file or database and manipulating that data from an Applet or a Java Application, but it is a different matter all together getting data from an application.
    Here are a few tutorials on File I/O and JDBC:
    http://java.sun.com/docs/books/tutorial/jdbc/index.html
    http://java.sun.com/docs/books/tutorial/essential/io/index.html
    -Merwyn,
    Developer Technical Support,
    http://www.sun.com/developers/support.

  • How to automate the execution of several programs and use their output

    Dear java members,
    I am trying to figure out how to get data from a file, database, or program and use that information in another program. Can you help please?
    I have looked through several texts and while the information is there somewhere I have not found the specific capabilities or examples that explain how to do this.
    I want to learn how to do this with objects.
    The specific applications I am working with are the GIS (Geographic Information System) suite of ESRI products such as ArcInfo and ArcView.
    I am working with simulators for hydrologeology (ground water) and other geophysical phenomenae. Programs for decisions and assessment of probability such as found in geostatistical analyses packages. Drawing programs and data manipulation programs such as spreadsheets in windows and scripting languages found in most Unix packages.
    I want to be proprietary platform free! I want to be accessing apps and or data wherever they are and in whichever form they are in or best used.
    Web techniques and protocols are where I think most of my effort will be focused.
    One of the mediums (media) that I expect to use a lot is XML.
    If I can find a simplified (generalized) explanation how this is done and how the parts fit together through and or with objects. If I can find references to texts and examples I will be very appreciative and very much less confused.
    I am interested in using the Java programming language.
    Thank you
    ctavares1

    Hello Tavares,
    What you seek can be done, but before that you must know from where you want to take the data. In what form you will get the data in and where you want to use it and how.
    Your problem is what we call an architectural issue. If possible please write to me at [email protected]
    With the above information - I shall be able to help you to some extent.
    Ironluca

  • Calling another program and waiting for output

    Hi,
    I'm writing a program that passes a file created for an application called Net Sim but has to wait for the output. Net Sim lies in another directory from the java files and I don't know how to call the program with the file created as a parameter, such as:
    ns2 network1.tcl
    where 'ns2' is the dos command to run net sim and 'network1.tcl' is a file passed as a parameter to the program.
    I've tried
    try{
    Runtime r = Runtime.getRuntime();
    r.exec(" <directory> ");
    }catch(IOException e){
    System.out.println("Error " +e);
    This doesn't work though and I could use some help, as well as how to save the file created by the program in another directory.
    Finally, I need to know how to make the program wait for the output from net sim which is a file I intend to use. Can I do this with a while loop etc.?
    I thank you in advance for any help,
    Regards,
    Gary.

    Here's an article from JavaWorld describing some of the pitfalls when using Runtime.exec() that might help you:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html

  • Call tcode KSB1 in a custom program and modify its output

    I was searching the forum for finding a way to create a program that has all details from KSB1 and some details from CJ13 (WBS details) and found some related posts. But none of the posts had any details on how to actually achieve this.
    I have to do a similar thing of getting the KSB1 output and add WBS details for each line item and then give the final output.
    If you have already done this before, please elaborate on the steps how you achieved it.
    Please specify the SUBMIT that you had written to call KSB1. If I can have all details from KSB1 in my memory, then I can read that in my program and add WBS details and give the output.
    Below is what I am doing but it gives the same error as one of you had - transaction code not defined.
    DATA: FCODE TYPE SY-TCODE VALUE 'KSB1'.
    SUBMIT RKAEP000 WITH SY-TCODE = FCODE.
    Any help would be appreciated. Thanks.
    Regards,
    Shipra

    Hi,
    try this code it will work..
    the data is stored in txtlines format the data by the field wise.
    * Data Declaration
      DATA:lt_listobject TYPE TABLE OF abaplist,
        l_tab_lines TYPE i.
      DATA: txtlines(1024) TYPE c OCCURS 0 WITH HEADER LINE.
      SUBMIT rkaep000                      "the program name
         USING SELECTION-SET 'BPC TEST'          "Pass varint BPC Test
               EXPORTING LIST TO MEMORY AND RETURN.
    * Read list from memory into table
      CALL FUNCTION 'LIST_FROM_MEMORY'
        TABLES
          listobject = lt_listobject
        EXCEPTIONS
          not_found  = 1
          OTHERS     = 2.
      IF sy-subrc  0.
    *   Error in function module &1
      ENDIF.
    *Spool content in Ascii format
      CALL FUNCTION 'LIST_TO_ASCI'
        TABLES
          listobject         = lt_listobject
          listasci           = txtlines
        EXCEPTIONS
          empty_list         = 1
          list_index_invalid = 2
          OTHERS             = 3.
      CALL FUNCTION 'WRITE_LIST'       "Display report same as in KSB1... else not required
      TABLES
        listobject = lt_listobject
      EXCEPTIONS
        empty_list = 1
        OTHERS     = 2.
    CALL FUNCTION 'LIST_FREE_MEMORY'
      TABLES
        listobject = lt_listobject.
      LOOP AT txtlines.   "data will be stored in this..
        " split the txtlines-tdline with | and move into another internal table and do the validation...
      endloop.
    Prabhudas
    Edited by: Prabhu Das on May 20, 2009 11:28 PM

  • Calling a transaction code in between the program and use the output

    Hi frnds,
              i want to call a transaction code in between the program   and pass the input .After getting the output, use that output in the program

    Hi Navin,
                     Why don't you sit with ABAPer he can explain better.
    Regards,
    HAri.

  • Problem with permissions, running programs and installing programs.

    I've been having trouble installing and running programs. Whenever I try to install a new program I have to make sure to right-click and select "Run as Administrator", which is something that didn't happen before. And while running programs, sometimes
    they don't work well (i.e. dropbox alerts me that it cannot run because of permission issues; calibre needs to run with Administrator level, otherwise it won't open my ebooks; the list goes on).
    I tried using the elevated command prompt and typin secedit
    /configure /cfg %windir%\inf\defltbase.inf /db defltbase.sdb /verbose to reset the permission settings, and it does not work (it tells me that some ignorable warnings occured).
    There's only one account in this machine and it has administrator level.
    Any thoughts?

    1. First of all, it is a bad habit to work with administrator account only. Use standard user account where programs allows for it.
    2. For third party programs contact respective support/forums. Some programs are not written in right way and may need admin account. I would avoid such programs.
    3. Elevated rights (Run as Administrator) is natural enhancement that comes with Windows version 6.x
    4. If you want to play risky role, disable UAC (not recommended). Step-by-step is here:
    http://www.petri.com/disable-uac-in-windows-7.htm#
    Regards
    Milos

  • Qosmio G20: How to run programs and films only on second display

    Is it possible to select which programs are displayed on the secondary display (tv)?? If so how.
    Also if I output a film to the tv it plays on the laptop sound and all. How can this be stopped i.e only play on the tv?
    Norskman

    Hi
    Usually you can change the display devices with the function FN+F5.
    Then you can change the option to notebook/LCD, LCD, notebook/TV, TV
    If you use the software like WinDVD so you have firstly change the display device and then use the software.

  • Calling the standard program in program and getting its output in int table

    Hi there,
    I have a requirement, where I need to call the standard program (of transaction CJI3) in my Y program. CJI3 transaction produces a ALV GRID output. I need to use that data for further processing. I am getting following problems:
    1. I tried to use SUBMIT ... EXPORTING TO MEMORY statement. I need to pass the company code for the selection, but the company code is in the dynamic selection. So not getting how to pass them.
    2. Just a doubt. Can we export the ALV GRID to the memory an retrieve it back using import?
    3. I did tried to use SUBMIT .....  statement using only the parameters which are on the selection screen. However the control went to CJI3 transaction and gave an error message 'Please select "from database" or "from archive" '. Did not understood that, any IDEA?
    Or is there any other way with which I can accomplish my requirement of getting the data in my program to manipulate, other than SUBMIT.
    Points will be rewarded.
    Thanks,
    Ganesh Khumse

    Hi,
    point 1:
    SUBMIT ... EXPORTING TO MEMORY will never work, because it displays the information in an ALV grid and that grid is waiting for user interaction for manipulating the information.
    point 2:
    no, you cannot export the content of an ALV grid to the memory
    point 3:
    must you get records in an internal table or must you feed the transaction, so that this one performs a task ??  for first option read below and for the other option you might work with BDC and Transaction Recorder.
    what you have to do is read the code of transaction CJI3 in order to understand what it does, where the information is read from and what is the internal table that passes the values to the ALV Grid. You might find a user exit in the code for manipulating that information or you might create an enhancement point if there´s no user exit.

  • Restoring all running programs and opened windows after restart.

    Is it possible to automatically restore upon logging in all applications, opened windows and documents running before a reboot of Leopard? It's rather convenient, especially when I have to reboot after an update of the system while working on a dozen of windows. Currently I have to relaunch them all one by one. It is a default feature of KDE, BTW.

    even tho it's so there
    This is a bit too close to a message I'm familiar with that can indicate a hijack on the PC. So just in case I think we'd better try a malware scan.
    Try downloading and installing the free version of Malwarebytes AntiMalware. Update your MBAM definitions and then run a full scan of the PC. (Takes about 2 hours on my Lenovo.)
    http://www.malwarebytes.org/mbam.php
    Does the scan find any infections? If so, please paste the contents of the log file for the scan in a reply here so we can have a look.

  • Possible? output a string from a java program into a running program

    I'm not sure if it is plausible, but this is my dilemma. My java program searches for street names in a specific region, then outputs the nearest street. I would like to synch this up with Google Earth, and output the street name into it, so it would go ahead and be able to search it right away. Is this possible, or should I attempt some other route?

    Check out my runCmd method. It gives an example of running another program and listening for the output. I built this to run javac and show the output in my custom editor.
    You'll see some classes in here that are not standard java classes, in particular InfoFetcher. Don't worry, this is just a utility I wrote for convenient handling of inputstreams. You can handle the inputstreams without it, but if you really want it, it's probably posted somewhere in these forums.
            private void runCmd(String cmd) {
                 try {
                      System.out.println("cmd: " + cmd);
                      Process p = Runtime.getRuntime().exec(cmd);
                      InputStream stream = p.getInputStream();
                      InputStream stream2 = p.getErrorStream();
                      InfoFetcher info = new InfoFetcher(stream, new byte[512], 500);
                      InputStreamListener l = new InputStreamListener() {
                           int currentLength = 0;
                           public void gotAll(InputStreamEvent ev) {}
                           public void gotMore(InputStreamEvent ev) {
                                String str = new String(ev.buffer, currentLength, ev.getBytesRetrieved());
                                currentLength = ev.getBytesRetrieved();
                                System.out.print(str);
                      info.addInputStreamListener(l);
                      Thread t = new Thread(info);
                      t.start();
                        InfoFetcher info2 = new InfoFetcher(stream2, new byte[512], 500);
                      InputStreamListener l2 = new InputStreamListener() {
                           int currentLength = 0;
                           public void gotAll(InputStreamEvent ev) {}
                           public void gotMore(InputStreamEvent ev) {
                                String str = new String(ev.buffer, currentLength, ev.getBytesRetrieved());
                                currentLength = ev.getBytesRetrieved();
                                System.out.print("(Error) " + str);
                      info2.addInputStreamListener(l2);
                      Thread t2 = new Thread(info2);
                      t2.start();
                 catch (IOException iox) {
                      iox.printStackTrace();
            }

  • GUI that open a Linux terminal, run commands and retrieve results

    Hi
    I am currently designing a GUI that should make it easier for users to execute a command line statement and read the information that is returned.
    I should not have any issues with the actual GUI, but I have not been able to find any examples to help with how to open a command terminal, enter a command and retrieve the results. I am aware that using a screen scraper is a possibility, but if anyone is aware of any examples to achieve this, that would be great.
    Thanks
    Matt

    Is the command line app a simple, straightforward one
    that just prints its output? (Eg. ls, dmesg, or any application
    that simply print results without reading input)
    If so, try this tutorial on calling a program
    and reading its output:
    http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html
    But if your commandline app is a rich-interactive one
    (eg. a full screen menu program or full screen text editor
    or something), then it's much much more complicated.

  • How can I generate clock in labview 8.0 and use it for programming and for hardware?

    I have to generate clock for synchronizing hardware with my program, so I need to to use this clock inside the program and as an output from A/D. The clock frequency has to be aproximately 3kHz.  

    *Insufficient information*
    First of all, i suspect that you are somehow believing that software can be timed by external signals. That is normally not the case, at least if you are using a standard Desktop PC.
    So please do not mix software with "data acquisition". Data acquisition can be configured to be "buffered" which means externally clocked. You can use the onboard clock for this or (in case of most hardware) any other TTL compatible "clocksource". This will ensure a clocked acquisition of the samples. The samples are then transferred to your PC and stored there as an array. So your program has to fetch the data "in time", but not "hardwaretimed".
    So please share some more information about:
    -What is your task
    -What is the hardware you are using
    -Software versions (driver, LV)
    -What is your current approach
    thanks,
    Norbert
    [Edit] There is a difference between "softwaretimed" and "hardwaretimes" acquisition. What i described in my reply would be the hardwaretimed acquisition, which i would say make the majority of all acquisitions. Softwaretimed acquisition describes a single point acquisition where a single sample is requested by the software. So each time the software requests a new sample, it will be acquired. This method heavily depends on the performance of the systems and does most often not exceed  few kHz (maybe 2 or 3). Furthermore, if you do not have a realtime or fpga, the acquisition if not deterministic which means that the samples are not acquired in a "static timeframe"; the delta t is not constant.....
    Single point acquisition is only worth for very slow signals (most often up to 1kHz) or control circuits.
    Message Edited by Norbert B on 12-01-2009 04:11 AM
    CEO: What exactly is stopping us from doing this?
    Expert: Geometry
    Marketing Manager: Just ignore it.

  • Can you play the guitar program and also run a keyboard at the same time using seperate outputs for both?

    I wanted to be able to play live on my electric guitar using mainstage and my keyboard player to use mainstage on the keyboard can this be done using the mainstage 2 on this computer?  Also if this can be done can you send the keyboard output and the guitar output seperatly to be able to be in different channels in the PA system?

    Hi
    Spatrick79 wrote:
    I wanted to be able to play live on my electric guitar using mainstage and my keyboard player to use mainstage on the keyboard can this be done using the mainstage 2 on this computer?
    Short answer: YES (but you will need to carefully consider how you organise your Patches with Guitar and Keys combinations, so that you both get the correct sounds at the same time)
    Spatrick79 wrote:
    Also if this can be done can you send the keyboard output and the guitar output seperatly to be able to be in different channels in the PA system?
    Yes, ideally using a multi-output audio interface. edit (with 2 outs for the guitar, and 2 for keys... you might also want another 2 pairs for monitoring)
    CCT

  • (1) Would like to pause syringe pump at certain volume while still collecting diameter data, (2) Would like to delay chart and numerical indicator output until after syringe pump is run

    Hello:
    I am using Labview to control a New Era Pump Systems automatic syringe pump and to record diameter measurements from a LaserMike optical comparator. My program is fully functional, the code is attached with all auxilliary files in the NE-50X folder. I mostly understand my program, I used drivers for the NE-50X pump found on the NI website to build my code and added to it as needed. My program currently does the following:
    After I push the white Run button, I am prompted for a file name. After I enter one, Labview begins collecting data from the LaserMike and syringe pump and outputs them to their respective numerical indicators and waveform charts. Then I can change the syringe pump flow rate and syringe diameter on the front panel. Once I push the green RUN button on the front panel, the syringe pump runs, and the balloon diameter vs. syringe volume XY graph begins to record. I can then reverse the direction of the pump and/or pause the pump however many times I like, while Labview still records diameter from the LaserMike. Pushing the red STOP button on the front panel terminates the program and stops the pump.
    Here are three things I would like to change about my program that I don't know how/what to do:
    1) I would like the LaserMike and syringe pump to output to their respective numerical indicators and charts only AFTER the green RUN button on the front panel has been pushed and the pump is running.
    2) I would like to be able to pause the syringe pump at two specific volumes while Labview continues to collect data from the LaserMike. I do not mind if I would have to push RUN to manually restart the program. I just want the pump to stall for a few seconds once the syringe pump dispenses a certain volume without the program terminating.
    3) I would like the program to terminate once a certain volume has been dispensed. I would also like the syringe pump to return to zero, its starting position, after each test so that each test is identical.
    If anyone has ideas about how to do any of these three things, your help is greatly appreciated.
    Attachments:
    Balloon Diameter.vi ‏132 KB
    NE-50X.llb ‏994 KB

    1.  You can set a boolean value when the Run button is pressed and use that boolean value to determine whether or not your indicator is updated.
    2.  You check the value of your syringe volume every loop iteration and pause the pump if a certain value is reached.  You can have the program wait for the user to press a button to restart.  You can also have it pause for a period of time and continue automatically.
    3.  Just like #2, you can wait for a certain value and stop the overall loop once that value has been reached. 
    Your program is an excellent candidate for event handling.  I have attached a link to a tutorial.
    Brian R.
    District Sales Manager
    Washington DC
    National Instruments

Maybe you are looking for