Java Runtime.Exec Can't Find Batch File Unless It Exists In Path
Java Runtime.exec is not the easiest method to use. In fact, it's much harder to use than any exec commands I have ever seen. I don't know if it is the heightened security features or what, but it really doesn't make life easy.
Today, I've been trying to execute a batch file using it by passing the batch file as a command and then setting the batch file's directory as the working directory. But I gget the following error message:
java.io.IOException: Cannot run program "Launcher.bat" (in directory "C:\transfer\briefcase\Cyrah Tasks\Prototype Launcher Task"): CreateProcess error=2, The system cannot find the file specified
The thing is, "Launcher.bat" is really in that directory. On the other hand, if I change "Launcher.bat" to "Prototype.bat", then this IOException doesn't occur.
After banging my head on the table for a long time, I finally figured out that I have a DIFFERENT "Prototype.bat" in the "path" environment variable. Java must have checked the path, found that one, and executed the current one in the working directory. What a strange way Java executes external programs?
Did your message disappear? Read the Forums FAQ.
Spam Control | * indicates required field
TrackBack only accepted from WebSite-X Suite web sites. Do not submit TrackBacks from other sites.
No TrackBacks yet. TrackBack can be used to link this thread to your weblog, or link your weblog to this thread. In addition, TrackBack can be used as a form of remote commenting. Rather than posting the comment directly on this thread, you can posts it on your own weblog. Then have your weblog sends a TrackBack ping to the TrackBack URL, so that your post would show up here.
Messages, files, and images copyright by respective owners.
Copyright © 1996 - 2018. All Rights Reserved.