20

What kind of problem(s) could cause Java's ProcessBuilder.start method to return an IOException with a note saying error=5?

Specifically, we've seen a remote customer system running some Java code along the lines of...

ProcessBuilder pb = new ProcessBuilder(cmdArray);
pb.redirectErrorStream(true);
Process p = pb.start();

...throw exceptions like this...

java.io.IOException: CreateProcess: C:\example\example.exe argument1 argument2 error=5
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
at java.lang.ProcessBuilder.start(Unknown Source)
at example_code_above

We have confirmed that the command noted in the exception, "C:\example\example.exe argument1 argument2" can be run successfully by hand via cmd.exe, so we are confident the command itself is not broken.

Matt Sheppard
  • 116,545
  • 46
  • 111
  • 131

4 Answers4

14

error=5 means one of:

1) file is not executable
2) file is not accessible

EDIT: wont throw exception
3) the command (example.exe) exits with exit code 5

Op De Cirkel
  • 28,647
  • 6
  • 40
  • 53
  • Thanks - Can you tell me where that information is available for future reference? – Matt Sheppard Jul 13 '11 at 05:55
  • [Windows predefined exit codes](http://en.kioskea.net/faq/2347-error-codes-in-windows) and a little bit of experimenting with ProcessBuilder for various cases – Op De Cirkel Jul 13 '11 at 06:03
  • 9
    I had this error on Windows 7 too. The reason ? Basically, I have tried to execute a folder rather than an executable :\ Dumb error – Stephan Nov 27 '11 at 19:09
  • http://stackoverflow.com/questions/39245238/errorcreateprocess-error-193-1-is-not-a-valid-win32-application can you tell about this – Aditya Vyas-Lakhan Aug 31 '16 at 09:19
9

Alexandr is correct, it's Windows security that's not allowing that process to run, but that powershell command didn't work for me. here's what I did:

  • Open up Windows explorer, and navigate to example.exe
  • Right click on it and choose "Properties"
  • Go to the "Security" tab and click the "Edit" button
  • Select your username in the top box and in the bottom one give "Full Control" or at least "Read & Execute"
  • Click OK to get rid of these boxes

Now your user can execute that program. Yay!

Ryan Shillington
  • 23,006
  • 14
  • 93
  • 108
2

Sometimes this happens because the path you put in code is not correct. For windows put "\\" as a path separator instead of "\" For example change path to "C:\\example\\example.exe"

Bo Persson
  • 90,663
  • 31
  • 146
  • 203
Harry
  • 4,705
  • 17
  • 73
  • 101
1

I have the same exception because of Windows UAC.

This can happen even if your account has administrator privileges.

To be able to run such command I had to use powershell to elevate privileges.

powershell start-process 'start.bat' -Verb RunAs
Alexandr
  • 474
  • 7
  • 13