How to get console output in exported application?

edited October 2013 in How To...

Hello all,

I've nearly finished my application to my own satisfaction, and I would like to export it to an executable to make it as easy as possible to run. However, a lot of feedback and information comes to the user via the console output, which is obviously not accessible (at least on Windows, which I have to use, haven't tested other OSs but that's irrelevant) once the application is exported. I've had a poke around on the forums and the Processing man pages but the only really relevant thread I could find was this one which I didn't fully understand and couldn't get to work. Other threads which looked tantalising (such as this one) are frustratingly 404'd after the archive.

Any tips?

Answers

  • Hi, one method which I just tried:

    I exported an application, and then run that application from command line. The application is called TEST and this is the code:

    void setup() {
      frameRate(1);
    }
    void draw() {
      println(millis());
    }
    void keyPressed() {
      int a = 0;
      println(55/a);
    }
    

    This is what I did to run the application: ./TEST >output.txt 2>&1

    The output.txt file then contains the millis() values and the divide by zero error when I press a key.

    Adding two greater-than signs in front of output.txt would append to the file, instead of overwriting it.

    Also, the TEST application file (at least in Linux) is a shell launch script, so you could add there the capturing of the output.

    If needed, you could then try to display the content of output.txt inside your program, reloading once in a while (if you need a console shown to the user).

    Is that what you are looking for?

  • Thanks, that is the sort of thing I'm looking for. I should have been clearer and explained that this has to work on Windows 7 so the shell syntax might be different, but that sort of method might be exactly what I need. I'll look into it this afternoon and if it works I'll accept your answer. :) I feel the trickiest part will probably be loading and displaying the text in the application, but I'm sure I can come up with something.

  • edited October 2013

    Interesting. I see that the win32 application is exported as .exe, but the win64 includes a .bat file. So one could modify this .bat file and add the output redirection. Or create your own batch file that redirects the output.

    Redirection is explained here: http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/redirection.mspx

    After a quick look it seems you should reverse the error output redirection expression: 1<&2

    Have fun :)

  • edited October 2013

    Hmm. My current thought process is that I will eventually write a python script to display the console output in a separate window (via tkinter or something). To begin with simple redirection experiments I started by doing cd to the folder containing the .exe and used the command (in cmd.exe):

    $ DPRB_Main_Vacuum.exe > logfile.txt 1<&2

    which, if I understand correctly, should take the console output from DPRB_Main_Vacuum.exe and write it to logfile.txt in the same directory, creating it if it does not exist. 1<&2 redirects error output into the standard output, which is then also written to the file.

    I played around with some controls in the sketch which I know should produce console output. For example, pressing certain buttons in the application when run via the processing IDE produces this message on the built-in console:

    Active

    Initialising serial comms...

    Stable Library

    =========================================

    Native lib Version = RXTX-2.1-7

    Java lib Version = RXTX-2.1-7

    Connecting on COM5

    Inactive

    Stopped

    Which is normal. The command I used in cmd.exe creates logfile.txt as expected, but it is just an empty file when I open it (after closing the .exe used to generate it). What am I missing here?

    Is it worth noting that when the .exe is run from within the command prompt there is no terminal output there? Just the GUI, no terminal messages at all.

  • "Is it worth noting that when the .exe is run from within the command prompt there is no terminal output there? Just the GUI, no terminal messages at all."

    It is the normal behavior of all Windows GUI programs.

  • edited October 2013

    Mm, that's what I thought. Thanks, PhiLho. So any idea as to why logfile.txt contains no output?

  • Answer ✓

    I think the .exe is running your sketch via Java and not passing through the standard output or error. If you use the .bat in the win64 application folder (which runs Java directly), you'll get a terminal window with the same output that shows in the PDE I believe. As far as I know, you can also copy the .bat into the win32 directory to is it to run the 32bit version.

  • Unfortunately the computer I'm running this on is 32-bit windows. An error dialog appears when I export and no win64 application folder is created. Is there a way of getting a generic "template" form of the .bat so I could write one for myself, or is it too complicated?

  • Bump the thread. I feel bad doing this but I could really use some help. Any ideas?

  • edited October 2013 Answer ✓

    For a sketch named Bah, the Bah.bat file contains:

    @ echo off
    java -Djava.ext.dirs=lib -Djava.library.path=lib Bah
    

    (Added space after @ to avoid a forum bug.)

  • Thank you very much, that's perfect. It appears to be doing exactly what I wanted now.

Sign In or Register to comment.