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:

Recommended Answers

All 5 Replies

See the API docs for the ProcessBuilder class. Also check the ErrorStream for the process to check for any errors. Go through this thread.

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?

First define what do you mean by "but it doesnt run. " Any exceptions, run time errors etc ?

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.

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.