Reputation: 25
How can a exe
file be executed in Java code in NetBeans?
I write a code to run a exe file in Java,
Process process = Runtime.getRuntime().exec( "cmd.exe /C start C:/Users/123/Desktop/nlp.exe" );
This code runs the file.
This file have some section that I can click it and run different part of it. Is it possible that I can use a code to access to that sections and run them in Java instead of clicking it?
edited code :
Process process = Runtime.getRuntime().exec( "cmd.exe /C start C:/Users/123/Desktop/nlp.exe" );
Robot bot = new Robot();
bot.mouseMove(100, 100);
bot.mousePress(InputEvent.BUTTON1_MASK);
bot.mouseRelease(InputEvent.BUTTON1_MASK);
Upvotes: 0
Views: 4103
Reputation: 2105
You can chain commands like this
In this example I use "c:" then "dir" then "ipconfig". "cho end"
To keep the terminal open at the end :
Runtime.getRuntime().exec("cmd /c start cmd.exe /K \"c: && dir && ipconfig\"");
To automatically close it at the end :
Runtime.getRuntime().exec("cmd /c start cmd.exe /c \"c: && dir && ipconfig\"");
EDIT
in your case that would be :
Runtime.getRuntime().exec("cmd /c start cmd.exe /K \"C:/Users/123/Desktop/nlp.exe && whatever_other_commands_you_want\"");
Upvotes: 0
Reputation: 17867
Use java.awt.Robot
to generate a system mouse click for an external program.
There is no built-in way with Java to get an external window's coordinates, but it can be done using JNA. See this answer:
Edit
Your comments and editing are changing the question, which is making answering here almost pointless. Per your last edit to the question though, if I understand correctly, you are now asking if possible to somehow trigger an event in the external application with Java, without triggering the mouse click. In this case I think the answer is highly specific to the individual program.
If the event can be triggered via keypresses, then that might an another non-mouse option using java.awt.Robot
.
If the program generates/responds to a Windows Message (at the windows api level), you could possibly send the same message via JNA and the windows api SendMessage
. However, that can get complicated and requires that you are familiar with windows API and techniques for finding and working with those messages.
Upvotes: 0
Reputation: 1083
You can send a click signal to the system and specify its position on the screen. Check this question
Upvotes: 1