3

I am creating a process using the below 2 lines

Runtime rt = Runtime.getRuntime();
Process p = rt.exec(COMMAND);

where COMMAND = "program.exe". program.exe is on the system's PATH variable.

Now the problem is that this does not work only in Windows 2K8 R2. It works fine on every other flavour of windows (winXP, win2003)

The error reported is :

java.io.IOException: Cannot run program "program.exe": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(Unknown Source)
animuson
  • 53,861
  • 28
  • 137
  • 147
jumpa
  • 658
  • 1
  • 9
  • 22
  • http://stackoverflow.com/questions/5642892/java-getruntime-exec-an-exe-that-requires-uac might be relevant? – Michael Berry Aug 08 '11 at 19:57
  • If the problem isn't with your code then it's probably a permissions or system configuration problem, right? Does Win2K8 R2 impose any restrictions on a user's ability to spawn programs from other programs? – maerics Aug 08 '11 at 20:50
  • Are you able to run `program.exe` from a command line? Does it display UAC elevation dialog? Is `program.exe` in _Program Files_? There are two Program Files directories on 64 bit systems, and 32 bit processes usually don't see programs from 64 bit Program Files and Windows directories. Therefore are you using 64 bit JRE? – Alexey Ivanov Aug 11 '11 at 18:49
  • 2
    Have you tried explicitly specifying the path rather than relying on PATH? Also does your command string contain a 'gotcha' like "c:\thisdir\thatdir\myprog.exe" `\t` = tab. – rossum Aug 14 '11 at 16:07
  • Yes I can execute program.exe from command line. No UAC pop up also. If I set full path, then it works. But I want it to work without specifying the full path. There are no restrictions on spawning processes on that machine. So I do not know how to proceed with debugging :( – jumpa Aug 19 '11 at 08:59

1 Answers1

1

You can run the program manually from the command line. You can run the program from within the parent process using the full path specification. I would say we can assume the program runs properly.

What else could be different? The environment the parent process is running under perhaps? I would check the PATH before launching the process. You are using Java. Too many Java programs use batch files to launch the JVM process. This batch file could be mucking with the PATH variable.

If this is your program and no batch file in involved I would check the current working directory when you run the parent program. It could affect what gets found at runtime as well.

Ken Brittain
  • 2,255
  • 17
  • 21