hello folks. I m trying to call an exe from java code.

public void MyClass{
public void run(){
 Runtime rt = new  Runtime ().getruntime();
 Process p = rt.exec("c:\mylexicalanalyser.exe < SampleInput.txt ");

p s v m(){
 new MyClass();

mylexicalanalyser.exe was created by flex utility for windows.
mylexicalanalyser.exe runs in the background (Task Manager) but does not seem to analyze the input file(SampleInput.txt).

Please help.:confused:

8 Years
Discussion Span
Last Post by abhi_elementx

OK. Now I am able to call the exe. from my main() method.
But I have a form(using swing) where I have a button.
I try to call the exe from the click (button_mouseclicked()) method
but it doesnt run.
What shud I do?


You would have to do the same that you do in your previous effort in the main method. To detect the button click you would have to implement listeners in Swing and then do the same task within the method for e.g actionPerformed().
Read about the Swing Event Delegation Model, ActionEvents, Listeners etc if you are new to those.

Edited by mike_2000_17: Fixed formatting


What I did was I called the main method of the class file ,which calls my exe , inside my button_click event. I use the Netbeans IDE which automatically handles the listening. Cause I also have some code above the call to main which excutes(I create a txt file with the txtfield inputs from my form and then call the main method of the class which contains the call to exec("lexer.exe < SampleInput.txt")). I dont get any exceptions and I can see the exe running in the task manager.

This article has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.