0

When I'm running the code below I get the error:

Cannot run program "query.sh": CreateProcess error=2, The system cannot find the file specified, Please check below code

I'm not sure how I can diagnose the root cause for its failure. What should I do to resolve the problem?

ProcessBuilder pb = new ProcessBuilder(FILE_PATH+SHELL_SCRIPT_NAME,
        DB_INSTANCE,
        DB_USER, 
        DB_PASS, 
        DB_NAME,
        SQL_QUERY, 
        fileFormat.toString());
Process p = pb.start();
p.waitFor();
A4L
  • 17,353
  • 6
  • 49
  • 70
  • 1
    Make sure `query.sh` is in the classpath, or just give your app a full path to that file. – BackSlash Jun 07 '18 at 07:44
  • related: https://stackoverflow.com/questions/14999489/processbuilder-cannot-find-the-specified-file-while-process-can – rene Jun 07 '18 at 07:52
  • 1
    What are the values of FILE_PATH and SHELL_SCRIPT_NAME? – FrontierPsychiatrist Jun 07 '18 at 07:54
  • 1
    if `"query.sh"` is reflecting the exact value of `FILE_PATH+SHELL_SCRIPT_NAME` then this means that `FILE_PATH` is empty and the file your are trying to run `query.sh` is not located in the working directory of your progam. Please check the values of each variable you are using to build the path of the file to be executed and compare it to the location in the filesystem. – A4L Jun 07 '18 at 07:54
  • @BackSlash What does the *classpath* has to do with it? – lexicore Jun 07 '18 at 07:58

1 Answers1

0

Let me guess: The program works when you run it in eclipse/InteliJ but fails when you build a runnable jar using eclipse/Maven/gradle? In that case, make sure that case, make sure that query.sh is in the resource directory of your project (probably called res/main.

Otherwise, make sure that query.sh is in the working directory of your application or just specify the fully qualified file name of query.sh.

vatbub
  • 2,713
  • 18
  • 41