Note that there are some explanatory texts on larger screens.

plurals
  1. POHow can I redirect the STDIO to a GUI component on a java app?
    primarykey
    data
    text
    <p>On C I would simple create a couple of pipes and use dup2 to overwrite the std file descriptor, while on the other end I'd create a thread for each outputing pipes (sdtout, sdterr) on a infinite loop taking advantage of the blocking IO of pipes to updated the textArea/canvas fitting the propose of a console. As for the stdin, I would listen for key events on such component, writing those to the pipe.</p> <p>But how can I perform that on Java with swing?</p> <p>I can't mix native code as a project directive. I already broke many project directives so far, so I can't push on that...</p> <p>Also it would be cool to provide some level of terminal emulation, such as VT100, but how to inform the java app of such capability, on unix I would set the TERM envvar.</p> <p>On C I would do the following:</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;unistd.h&gt; #include &lt;pthread.h&gt; static pthread_t workers[2]; static void *_worker(void *file) { int c; if(!file) pthread_exit(NULL); while((c=fgetc(file))!=EOF) { // Sync and put C on the screen } pthread_exit(NULL); } int initConsole() { int stdin_pipe[2], stdout_pipe[2], stderr_pipe[2]; if(!(pipe(stdin_pipe)||pipe(stdout_pipe)||pipe(stderr_pipe))) { if(dup2(stdin_pipe[0], STDIN_FILENO)&lt;0) return -1; if(dup2(stdout_pipe[1], STDOUT_FILENO)&lt;0) return -1; if(dup2(stderr_pipe[1], STDERR_FILENO)&lt;0) return -1; pthread_create(&amp;workers[0], NULL, _worker, fdopen(stdout_pipe[0], "r")); pthread_create(&amp;workers[1], NULL, _worker, fdopen(stderr_pipe[0], "r")); // Register a handler within the toolkit to push chars into the stdin_pipe return 0; } return -1; } </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload