Reputation: 245
I have an executable called fingerVerification_fdu03 in my current directory. I want to run that executable from Java using the ProcessBuilder, so I do:
Process pb = new ProcessBuilder("fingerVerification_fdu03").start();
However it is saying that it cannot find the file, even though it is in the same directory as the java program. Normally, I can execute the execute fingerVerification_fdu03 through the linux terminal simply doing:
./fingerVerification_fdu03
and it will run. What am I doing wrong?
Update:
I tried adding the directory, but still getting the same issue. I did:
String workingDirectory = new String(System.getProperty("user.dir"));
File tempDir = new File(workingDirectory);
Process p = new ProcessBuilder("fingerVerification_fdu03").
directory(new File(workingDirectory+"//")).start();
Could there be something wrong with the extension of the fingerVerification_fdu03 file? I'm not sure how to find out what extension it has. It is a binary file and is not listing it's extension.
Upvotes: 0
Views: 902
Reputation: 272237
You execute the command in your prompt by specifying the current directory, since (most likely) your PATH
doesn't reflect that directory.
You should consequently set the PATH
(directly or indirectly) in your ProcessBuilder
invocation. e.g. you can modify the PATH in the environment map returned by the environment()
method, or you can amend the executable name to reflect the absolute or relative directory path (as you're doing on the command line)
Note that having the executable in the same dir as your Java program won't mean that you'll be able to execute it without specifying the directory somehow. PATH
doesn't contain the current directory (.
) by default, and there's an argument that it shouldn't, for security reasons.
Upvotes: 1
Reputation: 3190
Two known possibilities that could generate a FileNotFoundException , first one is that the file is realy not found in the specified folder , so try to ensure that you execute your java program from the correct folder or give the absolute path of your executable.second possibility is a problem of permission , so check that you execute your java program with a user that have the valid permission .
Upvotes: 0