File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java Micro Edition and the fly likes exec of batch file fails Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Mobile » Java Micro Edition
Bookmark "exec of batch file fails" Watch "exec of batch file fails" New topic
Author

exec of batch file fails

Allan Sorenson
Greenhorn

Joined: Aug 21, 2008
Posts: 10
I need to execute a batch file from my java code and am having trouble getting it to work on Windows CE.
Runtime.getRuntime().exec(mycmd) always throws the exception: java.IOExeception: CreateProcess: mycmd error=2

Testing I found that:
Runtime.getRuntime().exec("/Hard Disk/redit.exe") works, but
Runtime.getRuntime().exec("/Hard Disk/foobar.bat") fails as above.

foobar.bat exists and executes just fine from the command line (it's just a single echo statement).

Anyone know how I can get java/WinCE to cooperate?

* machine: LC7000 (X86 architecture)
* OS: WinCE 5.0
* jvm: CrE-ME V4.12 (Evaluation version)

Thanks!
Aum Tao
Ranch Hand

Joined: Feb 14, 2006
Posts: 210
This might help

http://www.javaworld.com/javaworld/jw-12-2000/jw-1229-traps.html


SCJP 1.4 85%
Allan Sorenson
Greenhorn

Joined: Aug 21, 2008
Posts: 10
THANK YOU, Prateek!

Toward the end of the article was the solution I needed. Specifically:
Runtime.getRuntime().exec("/windows/cmd.exe /C \"/Hard Disk/foobar.bat\"");

I had tried a similar suggestion from else where, but it involved creating the cmd.exe proc and sending it the desired command via a stream. The creation of the cmd.exe proc however, caused the interactive session to begin. The above simply executed the batch file.
Aum Tao
Ranch Hand

Joined: Feb 14, 2006
Posts: 210
You are welcome, Allan.

I suspected that solution but I thought you would understand it better with concrete examples.
 
Consider Paul's rocket mass heater.
 
subject: exec of batch file fails