Java.lang.Process input stream waiting until process is complete to print

I have tried to simplify this problem as much as possible. Basically, I have a java.lang.Process which executes a simple C program.
test.c
#include <stdio.h>
#include <unistd.h>
int main()
  printf("foo\n");
  sleep(2);
  printf("bar\n");
...The process has an input stream and error stream handler each on a separate thread. I have tried both buffered and unbuffered (BufferedReader, BufferedInputStream, InputStreamReader...) stream handlers. Both produce the same problem of waiting until the process has exited to receive anything from the process's streams.
The only time this does not happen is when I call fflush(stdout); after each printf(). This can't be a solution because the real application calls a massive C application which would require thousands of fflush()'s to be added. What is causing this to happen? This doesn't happen when the C program is executed from the shell. Is there a way the InputStream can be forced to extract from the stream?

hi.....
I have closed the output stream of the process as you told me to do...
The hitch is that, if my program contains only printf() statements,it works fine
as soon as scanf() statement is encountered within the C code,it is totally neglected,and the output comes as if no scanf() statement existed in the C code.
Consequently the thread doesnt wait for input which was bound for scanf() from the thread
the code...
    public void run()
     try
         PrintWriter out = new PrintWriter(socket.getOutputStream(),true);
         BufferedReader in = new BufferedReader(
                        new InputStreamReader(
                        socket.getInputStream()));
         try
                 Process p;
          p=new ProcessBuilder("./a.out").start();
                 PrintWriter exOut=null;
                 BufferedReader exIn=null;
          exOut = new PrintWriter(p.getOutputStream(),true);
          exIn = new BufferedReader(
                       new InputStreamReader(
                       p.getInputStream()));
              //String inputLine="", outputLine="";        
              String str="";
                 int c;          
              while(true)                   
                    //System.out.println("In While");
              str="";exOut.close();                  
                    while((c=exIn.read())!=-1)
                             str=str+(char)(c);
                                System.out.print(str);
                    str=str+(char)(0);
                    System.out.print(str+"outside");
                    out.print(str);
                    sleep(100);
                    try
                        int x=p.exitValue();
                          out.print(str);
               System.out.print("Bye 1");
                        String str1="Bye"+(char)(0);
               out.println(str1);              
               break;
                    catch(IllegalThreadStateException e)
                        //System.out.println("The Process has not ended yet");
                    //str=str+((char)-1);
                    //System.out.print(str+"Control reaches here too");
                    str="";
                    exOut = new PrintWriter(p.getOutputStream(),true);//I have tried to run the program without this also but the effect is the same
                    while((c=in.read())!=-1)
                        str=str+(char)(c);                                    
                    if(str.contentEquals(""))
                            System.out.print("Bye 2");
                            String str1="Bye"+(char)(0);
                            out.println(str1); 
                            p.destroy();
                            exOut.close();
                            exIn.close();
                            out.close();
                            in.close();        
                            socket.close();
                            break;
                    //str=str+(char)(0);
              exOut.print(str);
                    try
                        int x=p.exitValue();
                        System.out.print("Bye 3");
                        String str1="Bye"+(char)(0);
               out.println(str1);
                        break;
                    catch(IllegalThreadStateException e)
                        //System.out.println("The Process has not ended yet");
              /*while ((inputLine = in.readLine()) != null)
                    exOut.println(inputLine);
                    outputLine=exIn.readLine();
                    //outputLine=inputLine;
                    //out.println(outputLine);}*/                   
         exOut.close();
         exIn.close();
         catch(IOException e)
              System.err.println("Accept failed."+e);
         out.close();
         in.close();        
         socket.close();
     catch (Exception e)
         e.printStackTrace();
}

Similar Messages

  • Java.lang.IllegalStateException : output stream already retrived Error

    Hi All
    I am trying to integrate crystal reports 10g with oracle 10g AS.My application works fine on TOMCAT 4.1.31,but when I depoly in oracle 10G AS,it shows the following exception
    Java.lang.IllegalStateException : output stream already retrived.
    Any suggestions?
    Regards
    Mohan

    Hello,
    Awaiting help.
    Thanks and Regards
    Mohan

  • Java.lang.IllegalStateException : output stream already retrived.

    Hi All
    I am trying to integrate crystal reports 10g with oracle 10g AS.My application works fine on TOMCAT 4.1.31,but when I depoly in oracle 10G AS,it shows the following exception
    Java.lang.IllegalStateException : output stream already retrived.
    Any suggestions?
    Regards
    Mohan

    Hello,
    Awaiting help.
    Thanks and Regards
    Mohan

  • Schedule reports and wait until the report complete

    I have wrote a java program to call BO SDK to schedule several crystal reports (same report, run at once with different parameters) to an unmanage disk. The program run successfully and can generate the reports. I would like to add an email notification function once all the reports are generated. How can I know the status of all the reports is completed?
    Does anyone know the answer? Many thanks.

    Hi Grace,
    BO CMC has feature for e-mail notification
    goto CMC
    navigate to that report.
    rigth click>> Manage->>Default Settings-->>Notification. (Email Notification: )
    Email notification based on:
          A job has been run successfully .
                      Configure notification message
                                               Use the Job Server's defaults
                                               Set the values to be used here:
        A job has failed to run 
                       Configure notification message
                                            Use the Job Server's defaults
                                            Set the values to be used here:
    I dont know about doing all this through SDKs but you can try doing this step by step frist through CMC and then going for infovie and then your java program.
    See if this could achieve your reqiurements
    Thanks,
    Praveen.

  • Have system wait until GUI is completed

    I wrote a program to monitor a seniority list. If an odd last name, first name, etc is encountered, a gui opens to request the proper form of the name. The problem is that the program keeps running even though the gui has not yet been fililed out. How do I stop execution until the GUI is completed?
    Thanks
    Joe

    Make the dialog modal.

  • Wait until swf is completely loaded...

    I am trying to load several swf files into various containers.  In one scene I have used the following:
    createEmptyMovieClip("container1", 1);
    loadMovie("MC.swf", "container1");
    And I want to wait for it to load complete before moving to the next scene and doing the following one...
    createEmptyMovieClip("container2", 2);
    loadMovie("MC2.swf", "container2");
    Can anyone please please save me?!
    Thank you very much in advance,
    Marc

    If you want to know when loading is complete, use the MovieClipLoader class instead of the loadMovie method.  The MovieClipLoader class supports having listeners for loading events such as load completion.  It's been awhile, but I think if you look up the MovieClipLoader.addListener method there is a good example there that covers most of what needs to be done.

  • Runtime.exec error - java.lang.NullPointerException

    Hi,
    I am trying out the example code from javaWorld that shows how to use exec to execute external command. The problem is that I aways run into java.lang.NullPointerException on line that has "Process proc = rt.exec(cmd);" I have tried to run the code under Windows XP and Windows 2003; and I get the same error message. Any idea on what might be casing this?
    Thanks,
    // GoodWindowsExec.java
    import java.util.*;
    import java.io.*;
    class StreamGobbler extends Thread
    InputStream is;
    String type;
    StreamGobbler(InputStream is, String type)
    this.is = is;
    this.type = type;
    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();
    public class GoodWindowsExec
    public static void main(String args[])
    if (args.length < 1)
    System.out.println("USAGE: java GoodWindowsExec <cmd>");
    System.exit(1);
    try
    String osName = System.getProperty("os.name" );
    String[] cmd = new String[3];
    if( osName.equals( "Windows NT" ) )
    cmd[0] = "cmd.exe" ;
    cmd[1] = "/C" ;
    cmd[2] = args[0];
    else if( osName.equals( "Windows 95" ) )
    cmd[0] = "command.com" ;
    cmd[1] = "/C" ;
    cmd[2] = args[0];
    Runtime rt = Runtime.getRuntime();
    System.out.println("Execing " + cmd[0] + " " + cmd[1]
    + " " + cmd[2]);
    Process proc = rt.exec(cmd);
    // any error message?
    StreamGobbler errorGobbler = new
    StreamGobbler(proc.getErrorStream(), "ERROR");
    // any output?
    StreamGobbler outputGobbler = new
    StreamGobbler(proc.getInputStream(), "OUTPUT");
    // kick them off
    errorGobbler.start();
    outputGobbler.start();
    // any error???
    int exitVal = proc.waitFor();
    System.out.println("ExitValue: " + exitVal);
    } catch (Throwable t)
    t.printStackTrace();
    }

    What is System.getProperty("os.name") returning when you run on Windows XP or 2003?
    You are only filling in your cmd array when os.name is either Windows NT or Windows 95. In other cases, the elements of cmd are left as null.
    The documentation for Runtime.exec() says you will get a NullPointerException when elements of the array are null:
    http://apidoc.org/view/10563?a=exec%28java.lang.String%5B%5D%29

  • How to wait until setPage(number) is finished

    SR 3-8311228061
    When calling getStrings, found I need to iterate the pages of the doc/xls/etc
    However Autovue Support tells me that setPage() is asynchronous
    I asked how to wait until setPage() is complete, they suggested I post the question here
    Note, at the time its called the viewer (desktop version 20.2.2) is on the task tray, but not rendering the document
    Its only loaded to extract the text
    here is the blip of code
    for( curPage = 1; curPage <= pages; curPage++)
    vueBean.setPage( curPage ); //its necessary to call setPage even for page 1
    //If setpage fails stop (per Daniel/Oracle)
    int thisPage = vueBean.getPage();
    if( curPage != thisPage )
    //This message never shows up
    String msg = String.format("Pages[%d] thisPage[%d] curPage[%d] ", pages, thisPage, curPage);
    AdeptApplication.INSTANCE.publishEvent("file-event", msg,
    new SystemEvent(this.fileName, "GETTEXT_PAGEFAILED"));
    break;

    The code you have is to know whether changing pages succeeded or not, and unless you are trying to set a page number that is out of the page count it will always succeed
    So, yes, your test is the same as if (false)
    Now, page loading is done in an asynchronous manner
    1. you ensure that the page (the container for all the page artifacts) is created, synchronously
    2. the page content are streamed on another thread
    3. once the page is loaded, an event is sent VueEvent(VueEvent.FILEEVENT, VueEvent.ONPAGELOADED)
    So you should be able to query for info after you received the page loaded event
    Now, word documents are an special kind of documents, so you need to be aware of some specific issues.
    The same way ms-word does not know the total number of pages until the ENTIRE document is loaded, AutoVue will not be able to notify you either.
    And as Word, AutoVue allows you to display the pages that are already loaded, and you may query for some of its contents too.  BUT you can not query for page info when the page is been loaded (or obviously not yet loaded)
    The loading is a 2 phase one, part is done on the server (native code) and part is on the java side (display)
    So you will not be able to iterate
    for( curPage = 1; curPage <= pages; curPage++)
    simply because page count is not known.  You need to query doc info more than once.
    If page count = -1, you need to iterate for each page and then, test whether setPage() != getPage() and/or page count has been updated.

  • Need help with Exception in thread "main" java.lang.NullPointerException

    here is the error
    Exception in thread "main" java.lang.NullPointerException
    at stream.createFrame(stream.java:153)
    at chat.createMessage(chat.java:14)
    this is where the error is in stream
    public void createFrame(int id) {
              *buffer[currentOffset++] = (byte)(id + packetEncryption.getNextKey());*
    and this is where it comes from in chat
    outStream.createFrame(85);                    
    i just cant see whats causeing the exception

    spiderjava wrote:
    the variable state is assigned to test1. This variable(test1) is not initialized anywhere.It is initialized in the c'tor. Which is invoked after the "global" object and attribute initialization. So it is there, but comes too late.
    You should definitly not write a technical Java blog and post it all over the place.

  • Getting java.lang.Null pointer Exception when i close the pdf file.

    Hi,
    my application is java based thick client application.
    From my application, i am generating report file using crystal report tool.
    the report file is exported as pdf format and stored in my local macine. from this path, am displaying the report in a SWT browser.
    till now its working fine. when i close the browser, i am getting java.lang.null.pointer exception.
    i dont understand from this exception, printed in console.
    please help me.
    java.lang.NullPointerException
    at org.eclipse.swt.ole.win32.OleClientSite.onPaint(OleClientSite.java:921)
    at org.eclipse.swt.ole.win32.OleClientSite.access$2(OleClientSite.java:906)
    at org.eclipse.swt.ole.win32.OleClientSite$1.handleEvent(OleClientSite.java:131)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1027)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1012)
    at org.eclipse.swt.widgets.Composite.WM_PAINT(Composite.java:1424)
    at org.eclipse.swt.widgets.Control.windowProc(Control.java:3842)
    at org.eclipse.swt.widgets.Display.windowProc(Display.java:4541)
    at org.eclipse.swt.internal.ole.win32.COM.CoFreeUnusedLibraries(Native Method)
    at org.eclipse.swt.ole.win32.OleClientSite.releaseObjectInterfaces(OleClientSite.java:1084)
    at org.eclipse.swt.ole.win32.OleControlSite.releaseObjectInterfaces(OleControlSite.java:683)
    at org.eclipse.swt.ole.win32.OleClientSite.onDispose(OleClientSite.java:852)
    at org.eclipse.swt.ole.win32.OleClientSite.access$1(OleClientSite.java:847)
    at org.eclipse.swt.ole.win32.OleClientSite$1.handleEvent(OleClientSite.java:128)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1027)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1008)
    at org.eclipse.swt.widgets.Widget.release(Widget.java:804)
    at org.eclipse.swt.widgets.Composite.releaseChildren(Composite.java:755)
    at org.eclipse.swt.widgets.Widget.release(Widget.java:807)
    at org.eclipse.swt.widgets.Composite.releaseChildren(Composite.java:755)
    at org.eclipse.swt.widgets.Widget.release(Widget.java:807)
    at org.eclipse.swt.widgets.Widget.dispose(Widget.java:441)
    at com.siemens.med.cad.hqm.reports.ReportViewer$1.widgetDisposed(ReportViewer.java:273)
    at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:117)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1027)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1008)
    at org.eclipse.swt.widgets.Widget.release(Widget.java:804)
    at org.eclipse.swt.widgets.Widget.dispose(Widget.java:441)
    at org.eclipse.swt.widgets.Decorations.dispose(Decorations.java:446)
    at org.eclipse.swt.widgets.Shell.dispose(Shell.java:674)
    at org.eclipse.swt.widgets.Decorations.closeWidget(Decorations.java:308)
    at org.eclipse.swt.widgets.Decorations.WM_CLOSE(Decorations.java:1643)
    at org.eclipse.swt.widgets.Control.windowProc(Control.java:3789)
    at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:337)
    at org.eclipse.swt.widgets.Decorations.windowProc(Decorations.java:1576)
    at org.eclipse.swt.widgets.Shell.windowProc(Shell.java:1937)
    at org.eclipse.swt.widgets.Display.windowProc(Display.java:4528)
    at org.eclipse.swt.internal.win32.OS.DefWindowProcW(Native Method)
    at org.eclipse.swt.internal.win32.OS.DefWindowProc(OS.java:2366)
    at org.eclipse.swt.widgets.Shell.callWindowProc(Shell.java:477)
    at org.eclipse.swt.widgets.Control.windowProc(Control.java:3877)
    at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:337)
    at org.eclipse.swt.widgets.Decorations.windowProc(Decorations.java:1576)
    at org.eclipse.swt.widgets.Shell.windowProc(Shell.java:1937)
    at org.eclipse.swt.widgets.Display.windowProc(Display.java:4528)
    at org.eclipse.swt.internal.win32.OS.DefWindowProcW(Native Method)
    at org.eclipse.swt.internal.win32.OS.DefWindowProc(OS.java:2366)
    at org.eclipse.swt.widgets.Shell.callWindowProc(Shell.java:477)
    at org.eclipse.swt.widgets.Control.windowProc(Control.java:3877)
    at org.eclipse.swt.widgets.Canvas.windowProc(Canvas.java:337)
    at org.eclipse.swt.widgets.Decorations.windowProc(Decorations.java:1576)
    at org.eclipse.swt.widgets.Shell.windowProc(Shell.java:1937)
    at org.eclipse.swt.widgets.Display.windowProc(Display.java:4528)
    at org.eclipse.swt.internal.win32.OS.DispatchMessageW(Native Method)
    at org.eclipse.swt.internal.win32.OS.DispatchMessage(OS.java:2371)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3420)
    at com.siemens.med.cad.hqm.view.mainUI.HQMMainForm.buildMainShell(HQMMainForm.java:246)
    at com.siemens.med.cad.hqm.event.UserLoginEventHandler.loginDisplay(UserLoginEventHandler.java:240)
    at com.siemens.med.cad.hqm.event.UserLoginEventHandler.widgetSelected(UserLoginEventHandler.java:97)
    at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:228)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003)
    at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3823)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3422)
    this is the code i have written for display the report file in a browser:
    Display display = Display.getDefault() ;
         Shell shell = new Shell(display, SWT.RESIZE | SWT.CLOSE | SWT.MIN | SWT.MAX | SWT.APPLICATION_MODAL);
    shell.setText(reportTitle);
    shell.setLayout(new FillLayout());
    shell.setMaximized(false);
    shell.setSize(800, 600);
    Composite comp = new Composite(shell, SWT.NONE);
    comp.setLayout(new FillLayout());
    final Browser browser = new Browser(comp, SWT.FLAT);
    try {
    File file = new File(exportFile);
    URL url = file.toURL();
    browser.setUrl("file:" + url.getPath());
    } catch (MalformedURLException malURLEx) {
    // malURLEx.printStackTrace();
    throw new ProgrammingExceptionAdapter(malURLEx);
    shell.addDisposeListener(new DisposeListener() {
    public void widgetDisposed(DisposeEvent arg0) {
    File file = new File(exportFile);
    if (file != null && file.exists()) {
    file.delete();
    browser.dispose();
    shell.open();
    shell.setFocus()'

    TitiTruc, welcome to the forum. Please don't post in threads that are long dead. When you have a question, start your own topic. Feel free to provide a link to an old post that may be relevant to your problem.
    I'm locking this thread now.
    db

  • Calling an applescript inside a Javascript, waiting for it to complete before moving on.

    I've got a handly little applescript compiled as an app that performs an Adobe Illustrator action which exports the current file's artboard #1 to a specific location at 300ppi. I can even call it from a javascript... which is great because I want a javascript that will loop x times, changing text and exporting on each each loop. But, each loop will export a file with the same name... not a problem, I'll rename the file after each loop, and javascript will wait patiently for me the export to complete before moving on to the next step, right? Wrong! Javascript just keeps moving through the script.
    So, how do I get Javascript to wait until the AppleScript completes the export? I can't have it wait a specific amount of time...export might take between 2 and 180 seconds.
    My ideas:
    1) can the applescript fire some sort of event letting Javascript know to move on?
    2) Is there a Javascript equivalent to AppleScripts "do javavscript " command, which would allow me to move the Applescript code into my core javascript?
    3) I could kludge a stopwatch on the first loop, checking every 10 milliseconds to see if the exported jpg file has been written... then using that as a baseline timer to pause later loops (not great, because the file will exist while AI writes it, and JS may rename it and try to export the second loop before the first is done).
    for (z =0; z<copyArray.length; z++) {
    var jpgExt = "-01.jpg";
    var newExt = ([z] + jpgExt);
    var exportASfile = File('/Applications/Adobe Illustrator CS5.1/Presets.localized/en_US/Scripts/VCS_Specialty Scripts/StandardExport.app');
    exportASfile.execute();  // export the file
    renamedFile = new File(exportFile); //variable exportFile is a reference to the jpg being written by the export
    renamedFile.rename (exportFile.name.replace(jpgExt, newExt)   ); // replaces part of the filename with a new

    I'd love to stay in one language, but since we're stuck on CS5 here, I have to make do.
    My task for the script:
    1) pop up a window to collect: 1a) number of copies, 1b) custom text, 1c) choice of three radio buttons -- I can't figure out how to do this in AS besides popping up three separate dialogs, I have it working great in JS
    2) loop step 1, write a named text frame with an array value containing a concatenation of 1a, 1b, 1c  -- pretty easy in either
    3) loop step 2, export the file at a higher than 72ppi resolution with artboard -- currently controlled by an action, can't be done programmatically in either AS or JS using CS5
    4) loop step 3, rename the file to match what was written to the text frame -- again, pretty easy in either
    In CS5, neither JS or AS have the ability to control the resolution of a jpg when exporting.... just the scale. So an action is required.
    My window JS has some of the basic edittext, statictext, buttons, panels elements, not too tricky:
    var win = new Window ("dialog","Cover Copy Builder");
        win.orientation = "column";
        win.add ("statictext", undefined, "Copy and Format Instructions");
        var input = win.add('panel', [0,0,320,300],  undefined, {borderless:true} );
        win.add ("statictext", undefined, "Output Summary");
    etc.
    Is there an AS equivalent to this sort of window building construction?

  • Facebook videos do not play correctly until loading is complete!

    Does anyone else have this problem? Every time I try to play a Facebook video I have to wait until the video completely loads in order to view the video correctly. If I don't wait the sound will play but the video looks bad making it imposible to view. This is a safari problem because I am able to play videos correctly in Google Chrome.
    I currently have:
    OS X Yosemite 10.10.2
    MacBook Pro (13-inch, Mid 2010)
    2.4 GHz Intel Core 2 Duo
    8 GB 1067 MHz DDR3
    NVIDIA GeForce 320M 256 MB

    there's a new version of QuickTime (7.1.3) with iTunes seven, and the "green screen" effect is traditionally associated with a QT not liking the version of the video drivers installed on the PC.
    so it's worth checking to see if there are more current video drivers available for your PC. this document might be of some help with that:
    Updating the drivers on your Windows PC

  • Java.lang.Process output stream problem

    Hi, I have a program that starts a process (java.lang.Process) using the java.lang.Runtime.exec() and it attemtps to interface with it using the provieded io streams. I have both the output and error streams being handled on their own threads and I have a hashmap of output lines/command pairs that are checked so that when the process outputs certain lines to the console it feed the proper input into the process. My problem is that when I feed the input into the process it dosen't respond to it almost like the user hasn't pressed enter, The process hangs. I have tried using /n /r and permutations thereof but nothing works. The thread does read the lines from the process and does output to the process from what i can gather. Can you help me!
    here is some of the code..
    public void run() {
    try {
         //the process's output
         InputStreamReader isrOutput = new InputStreamReader(inOutput);
         //the process's input(our output)
         PrintWriter pw = new PrintWriter(outInput);
         String line = null;
         while(true){
              if(brOutput.ready()){
                   line = "";
                   while(brOutput.ready())
         line+=(char)brOutput.read();
                   System.out.print(line);
                   if(commands.containsKey(line)){
         pw.println((String)commands.get(line));
         System.out.println((String)commands.get(line));;
    } catch (IOException ioe) {
              ioe.printStackTrace();
    }Thanks

    Oops.. i forgot to flush my PrintWriter /blushing......... Thanks

  • Error processing XML request, java.lang.IllegalArgumentException

    Hi all,
    In my code I can successfully connect to server and send the content which is an XML content:
    param = java.net.URLEncoder.encode(s, "UTF-8");
    java.io.PrintWriter out = new java.io.PrintWriter(connection.getOutputStream());
    out.print(param);
    Read the response from server:
    java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(connection.getInputStream()));
    while((input = in.readLine()) != null)
    response += input + "\r";
    System.out.println("Client : received : "+response);
    Following is the response I receive from server:
    Client : received : <html><h1>Error processing XML request</h1>java.lang.IllegalArgumentException: No xml request posted</html>
    Has anybody know what the problem is? Why this error is issued?
    Any help is greatly appreciated.

    Dear legosa,
    Thanks so much for the replies. What you wrote makes absolute sence, w/o flush() or close(), it seems that I'm sending only balnk to output!
    I don't know how can I fix the 500 Internal Server Error; below is my complete code that does this part, can you tell me if you see sth. wrong in this code?
    param = java.net.URLEncoder.encode(aTrans.xmlDoc, "UTF-8");
    url = new URL("https://xml.test.surepay.com");
    connection = (HttpURLConnection)url.openConnection();                    
    connection.setDoInput(true);
    connection.setDoOutput(true);
    connection.setUseCaches(false);
    connection.setRequestMethod("POST");
    connection.setRequestProperty("Content-type", "application/x-www-form-urlencoded");
    String sLen = "" + param.length();
    connection.setRequestProperty("Content-length", sLen);
    connection.setRequestProperty("Accept", "text/plain");
    connection.connect();
    System.out.println("Client : Connected");
    java.io.PrintWriter out = new java.io.PrintWriter(connection.getOutputStream());
    System.out.println("Client : Writing Content");
    out.print(param);
    out.close();
    System.out.println(connection.getURL());          
    System.out.println(connection.getResponseCode() + " " + connection.getResponseMessage());
    System.out.println(connection.getURL());
    System.out.println("Client : Waiting for response from Server");
    java.io.BufferedReader in = new java.io.BufferedReader(new java.io.InputStreamReader(connection.getInputStream()));
    System.out.println("Client : Opened input stream");
    while((input = in.readLine()) != null)
    response += input + "\r";
    System.out.println("Client : received : "+response);

  • How to wait until the 1st part of the processing is done

    Hi,
    I had a hard time to combine two parts of processing in one .vi file, and thus would like to get some advice/help through the forum.
    Attached is the partial finished vi file I made. You can see that it is composed of two parts. The upper part is to run a bat file (check_result.bat), which generates a result.txt file. The lower part is to use the result.txt file as an input file, and check if the key word called "test case passed" is included in the result.txt file or not. So I want to run the upper part firstly, and then run the lower part after the upper part is finished.
    However, I don't know how to connect the two parts in a right way that the lower part only starts running after the upper part is finished. Any comments/help is highly appreciated.
    Thank you in advance.
    Xuedong 
    Attachments:
    question.vi ‏49 KB

    The magic of dataflow!
    All you need is a data dependency between the two parts. Often critical parts of each section contain error terminals, so you can just string em along in the proper order and each part must wait until the previous node has finished.
    In your particular case, the read operation has no error input, so you can recruit any other input. Create a fake data dependency by strategically placing a small sequence frame containing common code. The sequence cannot start until all code that provides imputs has finished, serving your purpose.
    Of course it seems silly to even try to read the file if the previous node failed. Right? So simply place the second part inside a case and hook it up to the error output. Now the second part (1) waits until the first part has finished AND (2) execute only of the first part succeeded. No sequence needed.
    All clear?  
    Message Edited by altenbach on 02-07-2007 02:34 PM
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    dataflow.gif ‏4 KB
    dataflow2.gif ‏4 KB

Maybe you are looking for

  • Hyper-V guest SQL 2012 cluster live migration failure

    I have two IBM HX5 nodes connected to IBM DS5300. Hyper-V 2012 cluster was built on blades. In HV cluster was made six virtual machines, connected to DS5300 via HV Virtual SAN. These VMs was formed a guest SQL Cluster. Databases' files are placed on

  • *Please Help* iTunes wont stay open

    When I open my iTunes, and the itunes store begins to load, the store and my library automatically close. It stays on for about a second, then closes by itsself. I cant even get to my library for more than two seconds without it closing. Please help,

  • Battery % display is inaccurate on my iPad since IOS6.0.1, when will this be fixed?

    I find that the battery % display is inaccurate on my iPad since ios6.0.1. Same is happening on my iPod touch. Today my battery was showing as 93%, I stopped the apps, did a power off and on again and the battery went back up to 98%. Maybe this is wh

  • Hiding screen fields

    m using PNP selection screen. i want to hide some of these fields. how can i do it.

  • I am not able to display or change the file after deleting the file

    Hi All, I am checking in the document to content category while creating the DIR. I tried to delete the file on my desktop and after i am unable to open the file in CV02N,It gives the below error: Error while executing "C:\ Firdosi\Desktop\gg.txt" I