bask185
December 14, 2023, 2:03pm
1
I am trying to run a batch file from my processing sketch, but I cannot get it done. I keep getting an exception.
I tried open()
, launch()
and exec()
and with several paths. I believe open()
is no longer used in Processing.
./flashArduino.bat
.\flashArduino.bat
flashArduino.bat
But nothing what I attempt gets the job done. Searching the web came up blank.
void flashProgram()
{
print("trying to run batch thingy") ;
try {
//launch("./flashArduino.bat");
String myscript = "./flashArduino.bat";
Runtime rt = Runtime.getRuntime();
Process pr = rt.exec(myscript);
}
catch( IOException c )
{
print("IOException , it fails") ;
}
}
The batch file is in the same directory as my Processing files.
How do I call/run the batch file from my Processing application?
1 Like
bask185
December 14, 2023, 3:07pm
2
I found that running this line from the sketch:
launch("rundll32 SHELL32.DLL,ShellExec_RunDLL " + "C:\\Users\\sknippels\\Documents\\hobbyProjects\\functionBloX\\flashArduino.bat") ;
actually launches cmd.exe and runs the script. But now there is something wrong with the paths. + i would like to use relative paths.
Inside the batch files I have this content. I just invoke arduino-cli.exe 2x
echo off
Arduino-cli\arduino-cli compile -b arduino:avr:uno .\arduinoProgram
Arduino-cli\arduino-cli upload ./arduinoProgram -b arduino:avr:uno -p COM4
pause
When double clicking it from the explorer, all is well. But when running the line with launch
This happens
C:\Users\sknippels\Documents\processing-4.0.1>echo off
The system cannot find the path specified.
The system cannot find the path specified.
Press any key to continue . . .
How do I use a relative path here? The absolute path cannot be used anyways.
Kind regards,
Bas
glv
December 15, 2023, 12:27pm
3
Hello @bask185 ,
There may be something here that can be useful:
Hello,
This worked for me:
/*
* Launch Example 1
* v1.0.0
* GLV 2021-04-12
* Launches Google Chrome
*/
void setup()
{
//Works:
//println(sketchPath("")+"data/go.bat");
//launch(sketchPath("")+"data/go.bat");
//Works:
println(sketchPath("")+"data\\go.bat");
launch(sketchPath("")+"data\\go.bat");
}
go.bat in \data folder:
REM notepad.exe
start "C:\Program Files (x86)\Google\Chrome\Application\chrome.exe" "www.howtogeek.com"
pause
How to format:
FAQ - Processing F…
:)
bask185
December 18, 2023, 2:08pm
4
It was not the solution that I needed, but it is surely helpfull. I needed this as well for the next step.
In the meantime I found out in that horrible batch language how to set relative paths.
SET mypath=%~dp0
echo "BUILDING"
%mypath:~0,-1%\Arduino-cli\arduino-cli compile -b arduino:avr:uno %mypath:~0,-1%\arduinoProgram
This %~dp0
and mypath:~0,-1
make total sense
Kind regards
Bas
Hi @bask185 . Although Windows uses the \ as directory separator, it accepts / . If you give it a path using / everything works fine. (With / it does not prompt you as you are entering paths in e.g. cmd window.) Using / in your Processing sketch avoids Java needing \ to be escaped.
1 Like