Wanting to read in stdout before Process Finishes

So, I am running an external script using java Runtime.exec that has a stdout. Now, I feed it into a BufferedReader and read by line, and it works fine. However, this script may hang as its processing, which is not something I can change. However, output should still be coming in, or it does on the terminal. But I can't read the BufferedReader until the Process is complete, then it proceeds to read it all at once.
So, my question is this. Does the Process have to finish before you can read in the stdout in java? If not, how would I go about it?

jking31 wrote:
Here is my java code:
Process pro = Runtime.getRuntime().exec(cmdArr, null, new File(dir));
InputStream stdOut = new InputStream(pro.getInputStream());
InputStream errOut = new InputStream(pro.getErrorStream());
InputStreamReader stdOutReader = new InputStreamReader(stdOut);
InputStreamReader errOutReader = new InputStreamReader(errOut);
BufferedReader stdOutBR = new BufferedReader(stdOutReader);
BufferedReader errOutBR = new BufferedReader(errOutReader);
while ((line = stdOutBR.readLine()) != null) {
System.out.println(line);
while ((line = errOutBR.readLine()) != null) {
System.err.println(line);
}I am fully aware of the fact that this should be threaded to prevent problems, but I am going to be using this to update a JTextArea on a Swing GUI that is not thread safe. Then you should have a Thread for each Stream and update the Swing component with each line using SwingUtilities.invokeLater(). That is what I do and it works great.
My goal in the end is to have stuff print out to the Swing GUI while the process is going, but what ends up happening is that the stdOutBR won't actually be accessible until the Process finished, then it prints it all,If this is being run in the Swing event thread then of course this will happen since you are holding up the Swing event thread until you have read all the data. You should use a Thread and use SwingUtilities.invokeLater() to append each line.
If this is not being run in the Swing event thread then you must make sure that the native program is flushing it's stdout after each line.
but if I were to run this same code on the command line, I get output immediately, telling me what's going on before it starts to hang on a 30 second process.So it sounds like you should use a Thread for each stream and SwingUtilities.invokeLater().

Similar Messages

  • My wife and I each have an iPhone and an iPad Mini.  We have separate iTunes accounts.  She just finished reading a book on her iPad Mini.  Now I want to read it on my iPad Mini.  How can I get the book on my iPad Mini?

    My wife and I each have an iPhone 4s and an iPad Mini.  We have separate iTunes accounts.  She just finished reading a book on her iPad Mini.  Now I want to read it on my iPad Mini.  How can I get the book on my iPad Mini?

    Thank you for your reply Domingo.  Your suggestion worked as far as sending me a link to buy the book at iTunes.  But it did not allow me to download the book from my wife's account.  I did finally get an answer from Apple.  It took an entire day of emailing back and forth and the final answer was relatively easy once Apple finally decided to give up the solution.  Basically, you have to open ibooks and sign out.  Then you have to sign into ibooks using the book purchaser's Apple ID and password.  Then you can download the book onto your device.  Not too bad, huh?  It only took a whole day of Apple people sending me wrong instructions before they figured it out.  Geez.  What a disappointing experience.

  • I want to make a duplicate of my IMovie before I Finish it,but it won't let me (shaded)

    I want to make a duplicate of my IMovie before I Finish it,but it won't let me (shaded). What do I need to do yet?

    Try leaving your Project and go to the Project Library View. Select your project in the Project Library. You can then right-click/Duplicate Project or FILE/Duplicate Project.

  • TS3274 I get on the internet with my Ipad3 and when I start typing in the search box the ipad guess' what I want before I finish typing and goes to the internet. How do I fix that?

    I get on the internet with my Ipad2 and when I start typing in the search box the ipad guess' what I want before I finish typing and goes to the internet. How do I fix that?

    Yes if you purchase the tethering data plan for your iPhone. See:
    iPhone: System requirements for Personal Hotspot

  • HT201210 A message appeared on our Ipad wanting to know if we wanted to upgrade to 6.0 but just before it finished it locked up and now I can't get it to come on.  When I connect it to Itunes it tries to restore but then I get a message that says it isn't

    A message appeared on our I Pad wanting to know if we wanted to upgrade to 6.0 but just before it finished it froze up.  Then when I tried to restore it conneting to ITunes it said it wasn't eligible to be restored.  ????

    What to Do When Your iPad Won't Turn On
    http://ipad.about.com/od/iPad_Troubleshooting/ss/What-To-Do-When-Your-Ipad-Wo-No t-Turn-On.htm
    iOS: Not responding or does not turn on
    http://support.apple.com/kb/TS3281
    iPad Frozen? How to Force Quit an App, Reset or Restart Your iPad
    http://ipadacademy.com/2010/11/ipad-frozen-how-to-force-quit-an-app-reset-or-res tart-your-ipad
    iPad: Basic troubleshooting
    http://support.apple.com/kb/TS3274
    iOS: Resolving update and restore alert messages
    http://support.apple.com/kb/TS1275
    iPad: Unable to update or restore
    http://support.apple.com/kb/ht4097
     Cheers, Tom

  • From an Oracle form, I want to read a text file.

    From an Oracle form, I want to read a text file. In the form on a button press I have:
    declare
    in_file Text_IO.File_Type;
    linebuf VARCHAR2(1800);
    filename VARCHAR2(30);
    BEGIN
    filename:=GET_FILE_NAME('U:\ora_devl\pps\work\a.txt', File_Filter=>'Text Files (*.txt)|*.txt|');
    in_file := Text_IO.Fopen(filename, 'r');
    LOOP
    Text_IO.Get_Line(in_file, linebuf);
    -- :text_item5:=:text_item5||linebuf||chr(10);
    Text_IO.New_Line;
    END LOOP;
    EXCEPTION
    WHEN no_data_found THEN
    Text_IO.Put_Line('Closing the file...');
    Text_IO.Fclose(in_file);
    END;
    It gets an ORA-302000. I suspect the problem starts with the GET_FILE_NAME because when I comment out everything but that, It processes endlessly never ending.
    Forms [32 Bit] Version 11.1.1.3.0 (Production)
    Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - 64bit Production
    What can you tell me? Thanks

    GET_FILE_NAME will try to open an "Open File" dialog on the server, which obviously can't happen. If you want to use that type of behavior you need to use WebUtil and the function CLIENT_GET_FILE_NAME. Example:
         filename := CLIENT_GET_FILE_NAME('C:\', File_Filter=> 'Text Files (*.txt)|*.txt|All Files (*.*)|*.*|', dialog_type=> OPEN_FILE);Refer to the Builder Online help for more details. You can also refer to the demo which is available here:
    http://www.oracle.com/technetwork/developer-tools/forms/downloads/index.html
    More information here:
    http://www.oracle.com/technetwork/developer-tools/forms/webutil-090641.html
    Also, it appears that you are attempting to use a mapped drive ("U"). Although this can be made to work, it is not recommended and in some cases will not be supported. If you need access to remote files, you should use some other mechanism to bring the file to the local machine before manipulating it.

  • Sender jms adapter-archiving before processing the message

    Hi,
    Do we have any option in Sender JMS adapter to archive the message before processing the message?
    I have searched in sender JMS adapter (XI7.0) settings, but couldn't find any option.
    My assumption is whether any option provided in configuration setting of adapter engine or any other alternatives.
    Thanks,
    Srini.

    Hi Srini.
    Here is the code. But you may prefer the EAR module, just for deploy. I need your email to send it to you.
    If you want to create it yourself follow the steps in this guide and paste the code:
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/f013e82c-e56e-2910-c3ae-c602a67b918e
    When you configure the module in the JMS sender communication channel you have to spedify 2 parameter for the log file location:
    "file.path" (XI server file system path) and "file.name"
    CODE:
    package com.bfa.af.modules;
    import java.io.FileWriter;
    import java.io.IOException;
    import java.io.PrintWriter;
    import java.util.Date;
    import javax.ejb.CreateException;
    import javax.ejb.SessionBean;
    import javax.ejb.SessionContext;
    import com.sap.aii.af.mp.module.Module;
    import com.sap.aii.af.mp.module.ModuleContext;
    import com.sap.aii.af.mp.module.ModuleData;
    import com.sap.aii.af.mp.module.ModuleException;
    import com.sap.aii.af.ra.ms.api.Message;
    @author ibermatica
    public class BFATraceModule implements SessionBean, Module {
         private SessionContext myContext;
         public void ejbRemove() {
         public void ejbActivate() {
         public void ejbPassivate() {
         public void setSessionContext(SessionContext context) {
              myContext = context;
         public void ejbCreate() throws CreateException {
         public ModuleData process(ModuleContext moduleContext, ModuleData inputModuleData) throws ModuleException
              FileWriter outFile;
              try
                   Date date = new Date();
                   String filePath = moduleContext.getContextData("file.path");
                   String fileName = moduleContext.getContextData("file.name");
                   outFile = new FileWriter(filePath + System.getProperty("file.separator") + fileName, true);
              catch (IOException e)
                   e.printStackTrace();
                   throw new ModuleException(e);
              PrintWriter out = new PrintWriter(outFile, true);
              try
                   out.println("--- Start of message ---");
                   //Get message content.
                   Message data = (Message)inputModuleData.getPrincipalData();
                   if(data.getDocument() != null)
                        out.println(data.getDocument().getText());
                   else
                        out.println("Empty message.");
                   out.println("--- End of message ---");
                   out.println("Total characters: " + data.getDocument().getText().length());
              catch(Exception exc)
                   out.println(exc.toString());
              finally
                   if(out != null)
                        out.close();     
                   if(outFile != null)
                        try {
                             outFile.close();
                        } catch (IOException e1) {
                             throw new ModuleException(e1);
              return inputModuleData;

  • How to use DDL-Operations in before processing the form

    I want to drop and create a sequence when i make a form with
    WEBDB at the part "before processing the form" where i can add a
    PL/SQL code in a varius text area.
    Sybille Krvnert

    not sure in webdb how to do that, but I think you can put the
    code in the before proccessing form and after processing form
    block. In portal that should work, or you can place code in the
    button events for the save/insert/update buttons to do that like
    this:
    create sequence .....
    doInsert;
    drop sequence ....

  • Urgent to UPLOAD teh sapscritp only upload pls read query fully before answ

    urgent to UPLOAD teh sapscritp only upload pls read query fully before answering the query so as to avoid unwantd and unnecessry answers
    i want to load a external ITF script file to SAP and there is no way i want to donload it , i just want to load a external script file named zeg.itf to sap
    pls tell me the whole process as ih ave tried all programs none worked
    1) tell me the process to upload frm rstxscrp... step wise
    it asks for some dev class and wheni give it i doesnt move ahead .. so thts why i asked for the whole process...
    2) by any other program
    3) i knw the program names rstsr3tr a nd rstxscrp what is the diffrence between the two
    and plse let me know the whole process to upload?
    regards
    Arora

    Hi,
    1. selected the radio button "form"
    2. Gave the name of my new sapscript form
    3. mentioned IMPORT
    4. ran the program.
    5. During the program i selected the file (.txt) from where the form would be uploaded from.
    6. Object was created and activated .
    In ur case , u r saying that it is asking for the development clas, so please provide the same...
    It's nothing but the package name...
    If u dont have idea regarding the development class., save it to "$tmp" (as a local object)..That will be done...
    Cheers,
    Simha.
    Reward all the helpful answers...

  • I have a VI and an attched .txt data file. Now I want to read the data from the .txt file and display it as an array in the front panel. But the result is not right. Any help?

    I have a VI and an attched .txt data file. Now I want to read the data from the .txt file and display it as an array in the front panel. But the result is not right. Any help?
    Attachments:
    try2.txt ‏2 KB
    read_array.vi ‏21 KB

    The problem is in the delimiters in your text file. By default, Read From Spreadsheet File.vi expects a tab delimited file. You can specify a delimiter (like a space), but Read From Spreadsheet File.vi has a problem with repeated delimiters: if you specify a single space as a delimiter and Read From Spreadsheet File.vi finds two spaces back-to-back, it stops reading that line. Your file (as I got it from your earlier post) is delimited by 4 spaces.
    Here are some of your choices to fix your problem.
    1. Change the source file to a tab delimited file. Your VI will then run as is.
    2. Change the source file to be delimited by a single space (rather than 4), then wire a string constant containing one space to the delimiter input of Read From Spreadsheet File.vi.
    3. Wire a string constant containing 4 spaces to the delimiter input of Read From Spreadsheet File.vi. Then your text file will run as is.
    Depending on where your text file comes from (see more comments below), I'd vote for choice 1: a tab delimited text file. It's the most common text output of spreadsheet programs.
    Comments for choices 1 and 2: Where does the text file come from? Is it automatically generated or manually generated? Will it be generated multiple times or just once? If it's manually generated or generated just once, you can use any text editor to change 4 spaces to a tab or to a single space. Note: if you want to change it to a tab delimited file, you can't enter a tab directly into a box in the search & replace dialog of many programs like notepad, but you can do a cut and paste. Before you start your search and replace (just in the text window of the editor), press tab. A tab character will be entered. Press Shift-LeftArrow (not Backspace) to highlight the tab character. Press Ctrl-X to cut the tab character. Start your search and replace (Ctrl-H in notepad in Windows 2000). Click into the Find What box. Enter four spaces. Click into the Replace With box. Press Ctrl-V to paste the tab character. And another thing: older versions of notepad don't have search and replace. Use any editor or word processor that does.

  • I am trying to upgrade EPM 8.9(8.49.23) to EPM 9.1 (8.53.08). During dataconversion step the AE process finished succssfully in few seconds. When i see the log it says "There are no conversions to run for upgrade path PF89 (18028,10003)". Please let me kn

    I am trying to upgrade EPM 8.9(8.49.23) to EPM 9.1 (8.53.08). During dataconversion step the AE process finished succssfully in few seconds. When i see the log it says "There are no conversions to run for upgrade path PF89 (18028,10003)". Please let me know why it didnt do any conversion. Am i missing something?

    yes, that app engine didnt inserted any rows. So now when i tried to drill down i found that there was no data in the "new demo" database on table UPG_DATACONV. That is the reason for all this.
    When i applied required for upgrade patch in demo it said couple of patch already exists so those update i skipped. Now when i check upd877654 has a step which imports the data in this table. my change assistant told that the update is already available in my demo so i skipped. Now i am not sure what to do.
    I tried reimporting the data and running the analyzer again. But worried that there can be any issues due to this.

  • As I can sometimes do, I did not read the directions before delving into LR.  Now I find my self with image history in LR on 2 or 3 of my HD's.  I would like to now consolidate it on one HD but fear in doing so I will lose the images I have created within

    As I can sometimes do, I did not read the directions before delving into LR.  Now I find my self with image history in LR on 2 or 3 of my HD's.  I would like to now consolidate it on one HD but fear in doing so I will lose the images I have created within LR.  Is there a tutorio or some other way to get me back on track with this application?

    Your image history (if I understand you properly) is stored in your catalog file, and nowhere else, and so it is only on a single drive.
    Do you mean you have edited photos on multiple drives? This isn't a problem for Lightroom at all, the software doesn't care, and you can leave things just the way they are. But if it bothers you for some reason, you can move the photos to a single drive if you want. In Lightroom select the desired photos or folders (it's easier to do this using Folders) and drag them to the desired drive.
    Alternative if you will be moving lots of folders: Adobe Lightroom - Find moved or missing files and folders

  • I have gotten a giftcard for iTunes and I want to spend it but before I had a credit card giftcard and I spent it all and now I don't have a credit card and I just want to use thee iTunes one how do I delete the card on my iPhone

    I have gotten a giftcard for iTunes and I want to spend it but before I had a credit card giftcard and I spent it all and now I don't have a credit card and I just want to use thee iTunes one how do I delete the card on my iPhone

    Hello Clancbelle,
    It sounds like you have a credit card saved to your Apple ID payment information and you would like it to be removed from the account and set the payment method to None. You should be able to do this with the following article:
    iTunes Store: Changing your payment information
    http://support.apple.com/kb/ht1918
    Changing your payment information using an iOS device
    Tap Settings on the Home screen.
    Tap iTunes & App Stores.
    Tap your Apple ID. (If you aren't signed in, enter your Apple ID and password and tap Sign In.)
    Tap View Apple ID.
    Enter your Apple ID password.
    In the Edit section, tap Payment Information.
    Update the information that you want to change.
    Tap the Done button when you're finished.
    Thank you for using Apple Support Communities.
    Cheers,
    Sterling

  • Trouble updating to iOS 5 on my wife's iPhone 4 connected to our iM, right before download finishes downloading iTunes comes back with the error message Software corrupted during download.  Please check network settings and try again later.

    Trouble updating to iOS 5 on my wife's iPhone 4 connected to our iM, right before download finishes downloading iTunes comes back with the error message Software corrupted during download.  Please check network settings and try again later, however there was no problem updating my iPhone to iOS 5 through iTunes connceted to my dell laptop on the same wireless network.  What gives?

    Try disabling your firewall; both on your PC and the external Firewall/Router.

  • FTP sender adapter wait sometime before processing a message

    Hi,
    I want my FTP sender adapter to wait sometime before processing a message. This is needed in my case since the receiver of the message cannot consume message in, say two seconds, so I would like to configure a "time to wait before processing message" in PI since PI processes all of the files in folder without waiting another poll interval time if more than one exist.
    Is this possible in PI 7.0 sp16? 
    Regards,

    HI Tarik
    BPM is the solution for this problem. If you are not willing to use BPM other solutions are  Adapter module and Scripts
    You can write adapter module and use the threads mechanism. Thread.sleep can help you achieve this but you need to set this properly.
    Another method is Unix script. Let your actual directory be Dir1 and poll PI to Dir2. Use the script to write files from Dir1 to Dir2 one by one and with time gap. This will work for you.
    If you have PI system on Windows i prefer to go with Adapter module.
    Thanks
    Gaurav

Maybe you are looking for

  • How do I access a .txt file in Xcode for an OSX command line tool?

    I'm in school learning C and C++, and we have to read from and write to .txt files regularly. But I can't figure out how to open a .txt file in Xcode. if FILE *buffer = fopen(filename,"r"); where filename is a pointer to a char array holding the name

  • Error in the ABAP Code for Customer Exit Variable

    Could you please update me what is the wrong with the below ABAP Code developed for Customer Exit Variable in BW i created a Variable (ZVWKNO) of Customer Exit,Single Value ,Mandatory and Variable is ready for input In CMOD i had written the below Co

  • Issue in booting app server.

    I have installed tuxedo 8.1 on windows 2003 on PT 8.48.16 . Whenver I am trying to boot app server I m getting below error message . I had tried all the possible solution given on support site, but no luck. Beside that , I also get a pop-up image whi

  • Gl noted item

    Hi, for customer and vendor noted item, i know that they are from downpayment request for both customer and vendor. for gl, example in FBL3N, i also notice there is a noted items type in the selection screen. May I know what kind of noted item is thi

  • Sys.aq$_jms_text_message type queues message size limitations

    Are there any size limitations for enqueing text messages into a sys.aq$_jms_text_message type queue using AQ?