Archived

This forum has been archived. Please start a new discussion on GitHub.

How does stderr/stdout redirection work?

One of the Ice servers in the system I'm currently working on is a weird Java/SWI-prolog hybrid. If I redirect the output from that server using any of the Ice redirection properties (e.g., IceGrid.Node.Output), only the messages that are printed from the Java side show up in the logs; the messages that are directly printed by Prolog seem to vanish into the ether somehow.

If I run the program from the command line, using exactly the same executable values and environment as in Ice and with output redirection, I get the full output in the files. I mean, I do something like this (where "pl" is the Prolog executable; using a bash shell on linux):
pl main.pl -g run 1>test.out 2>test.err
and test.out and test.err contain everything printed by the server. But if I redirect through IceGrid, the corresponding files contain only the output produced by the Java side.

Is there anything obvious I should check to see what's going on here?

Thanks,

MEF

Comments

  • benoit
    benoit Rennes, France
    Hi,

    IceGrid uses the Ice.StdErr and Ice.StdOut properties to redirect the server output. The standard error/output is redirected by the server Ice communicator when it's initialized (with the java.lang.System.setOut/setErr methods). I suspect your prolog JNI library continues to log to the old stdout/stderr instead of using the new standard output/error.

    One solution to get this working would be the write a small wrapper to redirect stderr/stdout and then spawn the Java process. IceGrid would use this wrapper instead of directly using the java executable.

    Cheers,
    Benoit.
  • benoit wrote: »
    IceGrid uses the Ice.StdErr and Ice.StdOut properties to redirect the server output. The standard error/output is redirected by the server Ice communicator when it's initialized (with the java.lang.System.setOut/setErr methods). I suspect your prolog JNI library continues to log to the old stdout/stderr instead of using the new standard output/error.

    Yes, it looks like that was the issue. Unfortunately, the way this application is written, it's not really practical to use a wrapper -- the main program is actually written prolog, and it initiates the Ice connection through Java after it's done its own initialisation.

    For posterity, here's the solution I'm now using to capture all redirected output: after the Ice communicator has been initialised (in Java), I test whether the Ice.StdErr and/or Ice.StdOut properties exist. If they do, then I explicitly redirect the stderr and stdout in Prolog to files with similar names to the Ice files. (I originally thought of just redirecting prolog stdout to the *same* files, but that's probably a recipe for corrupting the output ...)

    MEF