0

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); 
2
  • 1
    I don't quite get your question but if nlp.exe is the application where you have to do a click selection then please check whether the application supports command line parameters. Commented Jul 9, 2014 at 12:33
  • no, It doesn't support it. Commented Jul 9, 2014 at 12:38

3 Answers 3

1

You can send a click signal to the system and specify its position on the screen. Check this question

Sign up to request clarification or add additional context in comments.

5 Comments

here the difficult part is to find the correct place to click
You have to compute it on your own. I don't think you can get any information about the content of the GUI.
thanks.I edited question and add code for using click.
it takes time to program run, so first robot click and then program run. what should I do to first run program and after that robot click?
You have to run the program first and wait for the UI to load (Thread.sleep or something)
0

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.

Comments

0

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\""); 

3 Comments

did you mean? " ( "cmd.exe /C start /K \"C:/Users/123/Desktop/nlp.exe ipconfig\"" )"
excuse me, why should i add other command in "whatever_other_commands_you_want"?
because I thought you would like to perform other operations than just the first command

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.