0

I designed an application with JavaFX/scenebuilder that connects to an arduino. The application has an option to update the Arduino with AVRdude. It does so by running a bat file with a command that executes AVRdude with a HEX file in a certain path. The user should be able to select a hex file, how would I go about realizing this?

The command is structured like: [config file] [parameters] -Uflash:w:[user selected hex file]:i

Where [user selected hex file] should be replaced by the path that the system gets from the filechooser.

I tried to put the command into a bat file and run it with Runtime.exec and Processbuilder but I can only get it working with a fixed command/path.

What would be the best way to run the command with the path as a variable? The filechooser code already works, its just how to inject the variable into the command.

lutkeveld
  • 49
  • 3
  • Can you post the code that builds the commandline? Also print out the contents of the commandline before it is executed so you can see what it is. – NormR Apr 07 '19 at 21:53
  • What do you mean by selecting HEX file? @lutkeveld – MS90 Apr 07 '19 at 22:25
  • 1
    You've managed to get `ProcessBuilder` working with a fixed command, all you need to do is change that code to accept variables and build the command using those variables. – Slaw Apr 08 '19 at 01:48
  • @MS90 Selecting a .hex firmware file – lutkeveld Apr 08 '19 at 09:17
  • @Slaw I packed the command in a bat file. This is my runexec command for example: Process process = Runtime.getRuntime().exec("path\\to\\command.bat");. But I have no idea on how to pass the path in the command as a variable. – lutkeveld Apr 08 '19 at 09:20
  • Some related questions: [Difference between ProcessBuilder and Runtime.exec()](https://stackoverflow.com/questions/6856028), [Executing another application from Java](https://stackoverflow.com/questions/3468987), and [Using parameters in batch files at Windows command line](https://stackoverflow.com/questions/14286457). – Slaw Apr 08 '19 at 09:34

0 Answers0