Jose Ramon
Jose Ramon

Reputation: 5386

The system cannot find the file specified executable from java

I have got a code which is stands for running an executable from java code. The program run smoothly until today. I dont know what I have changed however I am receiving the following error:

Cannot run program "\Release\program.exe" (in directory "I:\Release\"): CreateProcess error=2, The system cannot find the file specified

The code I am using is the following:

Process proc = rt.exec("Release\\program.exe", null, new File("I:\\Release\\"));

What could be the problem here? It used to work fine.

EDIT: Process proc = rt.exec("program.exe", null, new File("I:\\Release\\"));

I got the same error. If I command from the explorer

> I:\\Release\\program.exe

this works fine

Upvotes: 0

Views: 1570

Answers (2)

Mickael
Mickael

Reputation: 4558

Can you try this ?

// Java runtime
Runtime runtime = Runtime.getRuntime();
// Command
String command = "I:/Release/program.exe" ;
// Process
Process process = runtime.exec(command, null, new File("I:/Release"));

Upvotes: 1

NoRelect
NoRelect

Reputation: 608

Assuming your folder structure looks like this:

I:\Release\program.exe

Your code would then have to look like this:

Process proc = rt.exec("program.exe", null, new File("I:\\Release\\"));

EDIT: Try this instead:

ProcessBuilder proc = new ProcessBuilder("I:\\Release\\program.exe");
proc.start();

Upvotes: 2

Related Questions