uploading Code From java(eclipse)

PaulS:
And this is somehow Eclipse or avrdude's fault?

kinda mine but look;
i copy this command into command line it works:
C:\Users\Amatalamessinaj\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9/bin/avrdude -CC:\Users\Amatalamessinaj\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9/etc/avrdude.conf -v -patmega2560 -cwiring -PCOM12 -b115200 -D -Uflash:w:C:\Users\AMATAL~1\AppData\Local\Temp\arduino_build_698060/Final_servos.ino.hex:i

this is the error i get:
Cannot run program: CreateProcess error=2, The system cannot find the file specified

but when i do the same in java it doesn't:
runCommand(new String[]{"C:\Users\Amatalamessinaj\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9/bin/avrdude -CC:\Users\Amatalamessinaj\AppData\Local\Arduino15\packages\arduino\tools\avrdude\6.3.0-arduino9/etc/avrdude.conf -v -patmega2560 -cwiring -PCOM12 -b115200 -D -Uflash:w:C:\Users\AMATAL~1\AppData\Local\Temp\arduino_build_698060/Final_servos.ino.hex:i"});

i copy this command into command line it works:

this is the error i get:
Cannot run program: CreateProcess error=2, The system cannot find the file specified

Is THAT your definition of "works"?

PaulS:
Is THAT your definition of "works"?

ho really sorry this is the error of java no command line

i also test this in command line after moving avr files into java root project it works fine:
C:\Users\Amatalamessinaj\workspace\test>avrdude -Cavrdude.conf -v -patmega2560 -
cwiring -PCOM6 -b115200 -D -Uflash:w:test.ino.hex:i

but in java it give me the same error:
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified

Does your Java program have the necessary permissions to access the file?

It is not at all obvious from this error message "The system cannot find the file specified" what file it cannot find.

Why not write a short Java program just to list the file(s) you are trying to work with - that should help to figure what it is choking on.

...R

it was not a problem of file but i think it is somewhere between these 2 way of running command:
i'm trying to figure whats wrong but if u found before me i'll be honor to hear from my "stupid" error

this way it work:

Runtime rt = Runtime.getRuntime();
Process pr = rt.exec("avrdude -Cavrdude.conf -v -patmega2560 -cwiring -PCOM6 -b115200 -D -Uflash:w:Final_servos.ino.hex");

new Thread(new Runnable() {
public void run() {
BufferedReader input = new BufferedReader(new InputStreamReader(pr.getErrorStream()));
String line = null;

try {
while ((line = input.readLine()) != null)
System.out.println(line);
} catch (IOException e) {
e.printStackTrace();
}
}
}).start();

this way it doesn't work:
runCommand(new String[]{"avrdude -Cavrdude.conf -v -patmega2560 -cwiring -PCOM6 -b115200 -D -Uflash:w:Final_servos.ino.hex"});

static void runCommand(String[] cmd){
String s = null;
try {
Process p = Runtime.getRuntime().exec(cmd);
BufferedReader stdInput = new BufferedReader(new InputStreamReader(p.getInputStream()));
BufferedReader stdError = new BufferedReader(new InputStreamReader(p.getErrorStream()));

// read the output from the command
System.out.println("command out:\n");
while ( (s = stdInput.readLine ()) != null) System.out.println(s);
System.out.println("errors (if any):\n");
while ( (s = stdError.readLine ()) != null) System.out.println(s);

}catch (IOException e) {
System.out.println("something went wrong: \n");
e.printStackTrace();
}

}

after all thank you for the help all of you :slight_smile: <3

DrMessina:
this way it work:

That Java code is flawed. It may work most of the time but at some point it will jump up and bite you. If contains 3 of the traps described in the "When Runtime.exec() won't" article I gave you the reference to. One of the traps can cause a deadlock. You really need to read that article and implement the recommendations.