Output from javaws Process

  • Thread starter Andrew Thompson
  • Start date
A

Andrew Thompson

I am developing a tool to comprehensively check and
analyse JWS launch files. After well-formedness and
validation, and checking a slew of other aspects of
the launch files, the last check I want to offer is
the acid test, the result of a launch.

Unfortunately, when I attempt* to capture the output
of a javaws Process started by the app., it returns
no data at all, and the exit code is always '0'.

Questions:
1) Am I wrong in expecting javaws to return a non-zero
exit code for a failed launch? It might be that javaws
is simply reporting its own status 'yep, I'm just fine -
you asked me to launch a bogus JNLP - but that does not
affect javaws at all - bring it on..'.
2) Is the lack of output a problem in the code used, or
is javaws simply not dumping anything useful to the output?
(Expermiments from the command line suggest the latter,
but I felt it worth checking).
3) Are there any options I missed, to get javaws to be
more verbose about the launch?
4) Are there any better strategies to achieve the feature?
(A 'management' type API that allows me to access individual
launch exceptions would be ideal.) Note: Neither jdb nor
jconsole seems to be the answer (as far as I can determine).

* Here is a short code that should demonstrate the
failure..

<sscce>
import java.io.InputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;

class TestJavawsOutput {

public static void main(String[] args)
throws IOException {

ProcessBuilder pb = new ProcessBuilder(
"javaws",
// pops a dialog before launching the app.
//"-verbose",
"-wait",
"-J",
"-Xprof",
// a 'dud' JNLP file
"http://no.com/missing.jnlp");
// combine the output and error streams
pb = pb.redirectErrorStream(true);

Process p = pb.start();
InputStream is = p.getInputStream();
ByteArrayOutputStream launchResult =
new ByteArrayOutputStream();
byte[] b = new byte[1024];
int read = is.read(b);
while ( read>-1 ) {
launchResult.write(b,0,read);
read = is.read(b);
}
try {
int processResult = p.waitFor();
System.out.println(
"Exit code: " + processResult);
launchResult.flush();
System.out.println(
"'" + launchResult.toString() + "'");
} catch(InterruptedException ie) {
ie.printStackTrace();
}
}
}
</sscce>

Typical output:
From the dialogs that javaws shows the user..
<on-screen>
CouldNotLoadArgumentException[
Could not load file/URL specified:
http://no.com/missing.jnlp]
at com.sun.javaws.Main.launchApp(Unknown Source)
<on-screen>
From the command line
<cli>
Exit code: 0
''
Press any key to continue . . .
</cli>
 
A

Arne Vajhøj

Andrew said:
I am developing a tool to comprehensively check and
analyse JWS launch files. After well-formedness and
validation, and checking a slew of other aspects of
the launch files, the last check I want to offer is
the acid test, the result of a launch.

Unfortunately, when I attempt* to capture the output
of a javaws Process started by the app., it returns
no data at all, and the exit code is always '0'.

Questions:
1) Am I wrong in expecting javaws to return a non-zero
exit code for a failed launch? It might be that javaws
is simply reporting its own status 'yep, I'm just fine -
you asked me to launch a bogus JNLP - but that does not
affect javaws at all - bring it on..'.
2) Is the lack of output a problem in the code used, or
is javaws simply not dumping anything useful to the output?
(Expermiments from the command line suggest the latter,
but I felt it worth checking).
3) Are there any options I missed, to get javaws to be
more verbose about the launch?
4) Are there any better strategies to achieve the feature?
(A 'management' type API that allows me to access individual
launch exceptions would be ideal.) Note: Neither jdb nor
jconsole seems to be the answer (as far as I can determine).

10 minutes of experimentation confirmed the problem and
showed no obvious workarounds.

You may need to hack com.sun.javaws.Main to get a usable
return code.

Arne
 
J

John B. Matthews

[...]
1) Am I wrong in expecting javaws to return a non-zero
exit code for a failed launch? It might be that javaws
is simply reporting its own status 'yep, I'm just fine -
you asked me to launch a bogus JNLP - but that does not
affect javaws at all - bring it on..'.

That's what I'm seeing.
2) Is the lack of output a problem in the code used, or
is javaws simply not dumping anything useful to the output?
(Expermiments from the command line suggest the latter,
but I felt it worth checking).
[...]

There's some output on stderr:

import java.io.*;

/** @author John B. Matthews */
class ExecTest {

public static void main (String[] args) {
String s;
try {
Process p = Runtime.getRuntime().exec(
"javaws http://invaid.invaid/invalid.jnlp");
// read from the process's stdout
BufferedReader stdout = new BufferedReader (
new InputStreamReader(p.getInputStream()));
while ((s = stdout.readLine()) != null) {
System.out.println(s);
}
// read from the process's stderr
BufferedReader stderr = new BufferedReader (
new InputStreamReader(p.getErrorStream()));
while ((s = stderr.readLine()) != null) {
System.err.println(s);
}
p.getInputStream().close();
p.getOutputStream().close();
p.getErrorStream().close();
System.err.println("Exit value: " + p.waitFor());
}
catch (Exception e) {
e.printStackTrace();
}
}
}

HTH
 
M

Michael Rauscher

Andrew said:
Questions:
1) Am I wrong in expecting javaws to return a non-zero
exit code for a failed launch? It might be that javaws
is simply reporting its own status 'yep, I'm just fine -
you asked me to launch a bogus JNLP - but that does not
affect javaws at all - bring it on..'.

What's the exit code of javaws if an existing application terminates by
e.g. System.exit(5); ? (I can't try it at the moment)

Having read the documentation, at least using a combination of the
switches "-import" and "-silent" shall cause javaws to fail with exit
code 1 if a JNLP can't be imported.

Bye
Michael
 
A

Andrew Thompson

Thanks for your replies, folks. I have very limited internet time
at this instant, but will save the thread and look more closely at
them at home.
 

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

No members online now.

Forum statistics

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

Latest Threads

Top