I'm trying to run a simple prompt command froma java application.
No matter what I try, I alwasy receive a CreateProcess error=2.
This is my code:
File f = new File("C:/Users/my/path/to/the/executable/");
String[] commands = { "text.txt", "--command1" /* others commands */ };
// omitting try/catch
Process p = Runtime.getRuntime().exec("myprogram.exe", commands, f);
p.waitFor();
// other code
The exe takes as first parameter a .txt file, then it takes normal commands as --command1.
How can I get this working? Thanks in advance!
-
What error do you have?talex– talex2016年10月22日 10:20:47 +00:00Commented Oct 22, 2016 at 10:20
-
@talex, more specifically it is: Java.io.IOException: Cannot run program "myprogram.exe" (in directory "/thedirectory"): error=2, No such file or directoryLampione– Lampione2016年10月22日 10:23:32 +00:00Commented Oct 22, 2016 at 10:23
1 Answer 1
The directory parameter is not the path to the executable, it is the working directory, so if you are on command line, it would be the current directory you are in when you launch the command.
You need to specify the whole path in first parameter, or add it to the PATH environment variable