Using a message box to display errors

I have a program that uses Swing componants to make various system calls. I am wanting to display (or trap) any errors that occur while running the command and display the error(s) in a single message box.

Here is a sample of the code for one of my system calls...

privatevoid btn_CreatereplicaActionPerformed(java.awt.event.ActionEvent evt){

// TODO add your handling code here:

String Work = txt_Workdir.getText();

String Export = txt_Exportdir.getText();

String Host = txt_Hostname.getText();

String command = ("cmd /c multitool mkreplica -export -workdir " + Work +" -nc -out " + Export +" hostname:" + Host);

Process p =null;

try{

p = Runtime.getRuntime().exec(command);

}catch (IOException ex){

ex.printStackTrace();

}

}

Curretly if the user does something wrong when running the "command" the program just sits there (unlike a cmd prompt that displays the error). How do I get an error (if any) to pop up in a message box?

Thanks

[1477 byte] By [yelllow4ua] at [2007-11-27 11:04:51]
# 1

Get the InputStream of the process after running the command so you can get the process' output. Then read that and figure out if an error occurred.

hunter9000a at 2007-7-29 13:04:42 > top of Java-index,Java Essentials,New To Java...
# 2

I suspect the OP should read this article:

http://java.sun.com/products/jfc/tsc/articles/threads/threads1.html

filestreama at 2007-7-29 13:04:42 > top of Java-index,Java Essentials,New To Java...
# 3

ok....I just read that article and understood none of it.

yelllow4ua at 2007-7-29 13:04:42 > top of Java-index,Java Essentials,New To Java...
# 4

Alrighty then!

filestreama at 2007-7-29 13:04:42 > top of Java-index,Java Essentials,New To Java...
# 5

I tried something like this but the dialog never pops up...

private void btn_CreatereplicaActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

Object frame = null;

String result = null;

String Work = txt_Workdir.getText();

String Export = txt_Exportdir.getText();

String Host = txt_Hostname.getText();

String command = ("cmd /c multitool mkreplica -export -workdir " + Work + " -nc -out " + Export + " hostname:" + Host);

Process p = null;

try {

p = Runtime.getRuntime().exec(command);

} catch (IOException ex) {

ex.printStackTrace();

}

}

Scanner s = new Scanner(p.getInputStream());

while(s.hasNextLine()) {

sb.append(s.nextLine()+"\n");

result = sb.toString();

}

JOptionPane.showMessageDialog((Component) frame, result);

yelllow4ua at 2007-7-29 13:04:42 > top of Java-index,Java Essentials,New To Java...
# 6

OK.....I got some of it working.

private void btn_RenameActionPerformed(java.awt.event.ActionEvent evt) {

// TODO add your handling code here:

String VOBpath = txt_VOBpath.getText();

String CReplica = txt_Currentrepname.getText();

String NReplica = txt_Newrepname.getText();

String command = ("cmd /c multitool rename replica:" + CReplica + " "+ NReplica);

File filepath = new File(VOBpath);

Process p = null;

try {

p = Runtime.getRuntime().exec(command, null, filepath);

} catch (IOException ex) {

JOptionPane.showMessageDialog(null,

"Cannot Rename Replica: " + ex.getMessage(), "Error", JOptionPane.WARNING_MESSAGE);

return;

}

}

So far so good. Anyone know how to catch an application exception. For instance if I run this command from the DOS prompt without java and I "accidentally" screw up the command I get and error like:

Here is the command that is run from the DOS prompt...

multitool rename Boeing replica:Boeing2

Here is the error I get...

multitool: Error: Pathname not found: "Boeing"

When I run this from my Java program I am assuming that this would be an application error since its just a system call.

I tried something like....

catch (ApplicationException ex) {

JOptionPane.showMessageDialog(null,

"Cannot Rename Replica: " + ex.getMessage(), "Error", JOptionPane.WARNING_MESSAGE);

}

But when I add this code I don't get the error popping up like I would expect....Any ideas?

Thanks.

yelllow4ua at 2007-7-29 13:04:42 > top of Java-index,Java Essentials,New To Java...
# 7

just a bump

yelllow4ua at 2007-7-29 13:04:42 > top of Java-index,Java Essentials,New To Java...