Way to capture System.out in a *sandboxed* app.?

  • Thread starter Andrew Thompson
  • Start date
A

Andrew Thompson

System.out/err cannot be redirected in a sandboxed**
application(/applet).

Assuming you wanted to to show the end user the
System.out/System.err from a *sandboxed* app.*, how
would you go about collecting the information?

* Note - I am looking at launching apps. written by other
people, so I need to intercept/duplicate the normal
System.out/err they might use. The GUI might be
invoked by a 'full trust' app. - then the task is easy,
*but otherwise,* is there a (sandboxed) way to intercept
those streams?

**This (sandboxed) Applet is not allowed to set the
output stream..

<sscce>
import java.applet.Applet;
import java.awt.Label;
import java.io.PrintStream;
import java.io.ByteArrayOutputStream;

public class RedirectOutputInApplet extends Applet {

public void init() {
try {
PrintStream ps = new PrintStream(
new ByteArrayOutputStream());
System.setOut(ps);
} catch(Throwable t) {
add(new Label(t.getMessage()) );
}
}
}
</sscce>
 
C

Christian

Andrew said:
System.out/err cannot be redirected in a sandboxed**
application(/applet).

Assuming you wanted to to show the end user the
System.out/System.err from a *sandboxed* app.*, how
would you go about collecting the information?

* Note - I am looking at launching apps. written by other
people, so I need to intercept/duplicate the normal
System.out/err they might use. The GUI might be
invoked by a 'full trust' app. - then the task is easy,
*but otherwise,* is there a (sandboxed) way to intercept
those streams?

**This (sandboxed) Applet is not allowed to set the
output stream..

<sscce>
import java.applet.Applet;
import java.awt.Label;
import java.io.PrintStream;
import java.io.ByteArrayOutputStream;

public class RedirectOutputInApplet extends Applet {

public void init() {
try {
PrintStream ps = new PrintStream(
new ByteArrayOutputStream());
System.setOut(ps);
} catch(Throwable t) {
add(new Label(t.getMessage()) );
}
}
}
</sscce>

may be it would do if you run some program in a childprocess you could
redirect the output stream to your likings:

see Process and ProcessBuilder classes
 
R

Roedy Green

may be it would do if you run some program in a childprocess you could
redirect the output stream to your likings:

see Process and ProcessBuilder classes

IIRC exec is off limits to unsigned Applets too.

I think he is stuck using something other than System.out. And
displaying the results in a scrolling JTextArea.
e.g. log.print( String );
 
A

Andrew Thompson

Roedy said:
IIRC exec is off limits to unsigned Applets too.

Correct. Runtime.exec() and ProcessBuilder.start() both
throw security exceptions in sandboxed apps.
I think he is stuck using something other than System.out. And
displaying the results in a scrolling JTextArea.
e.g. log.print( String );

Logging is already implemented. If the child apps.
utilise the logger we provide, we are set. It was the
'legacy components' that use no logging that I am
more interested in at the moment.

But it seems there is no way. So I'll 'try' to redirect
the streams, then immediately after that (before the
'catch'), add the 'view output' menu item.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top