I am trying to send a command to windows from my java program, and I get an
error.
The pertinent (?) part of my code follows:
public boolean action(Event evt, Object arg)
{ if (arg.equals("Execute")){
inputText=(String)commandText.getText();
System.out.println(inputText);
try{
Runtime rt = Runtime.getRuntime();
//Process cp1=Runtime.getRuntime().exec(inputText);
//With the Runtime instance the program is run with the exec()
method:
Process process = rt.exec (inputText);
}
catch(IOException ee){
System.err.println(ee+" can't run command");
System.exit(1);
}
}
else return super.action(evt,arg);
return true;
}
I have written other java programs that successfully used this function, but
I don't know why this one doesn't work. Any suggestions?
Andrew Thompson - 29 Sep 2007 07:14 GMT
>I am trying to send a command to windows from my java program, and I get an
>error.
If that is a CodeIsDepressedException then the solution
is easy, we have drugs to treat that, in this day and age.
If it is something else, then you might progress the thread
by *stating* the exact exception, and perhaps even listing
a stacktrace that references the code lines that led to the
probem.
> The pertinent (?) part of my code follows:
A good way to make sure the code includes the
pertinent lines is to prepare an SSCCE.
<http://www.physci.org/codes/sscce.html>
...
>I have written other java programs that successfully used this function, but
>I don't know why this one doesn't work. Any suggestions?
Post an SSCCE with stacktrace.

Signature
Andrew Thompson
http://www.athompson.info/andrew/
Joshua Cranmer - 29 Sep 2007 15:08 GMT
> public boolean action(Event evt, Object arg)
If I remember correctly, this would be the event dispatch model in Java
1.0 deprecated by Java 1.1?
> I have written other java programs that successfully used this function, but
> I don't know why this one doesn't work. Any suggestions?
1. Try using the more recent, non-deprecated version of the event model.
It's only been around for five versions of Java, after all.
2. After that, what exactly is the clue that it is not working? An error
message? No output? "It doesn't work" is very vague and is nearly
impossible to fix without more information.

Signature
Beware of bugs in the above code; I have only proved it correct, not
tried it. -- Donald E. Knuth