Cynosure.X International LLC

:

Add Comment | Related Links | TrackBack
Related Content

Change Directory in Java Runtime.exec

Java's security is extremely strict. Whatever Windows batch file you execute, with the Runtime.exec () method, can't determine the current working directory, nor can it change directories. But here is a trick to get your batch files to work if you really have to change working directories . . .

Have Runtime.exec () called a batch file that in turn calls another batch file with the "command /c" directive. For example, if you have "Launcher.bat" and "Execution.bat", Put the following line in "Launcher.bat":

command /c Execution.bat

"Execution.bat" will be able to look at its current working directory and change it as well.

Chieh Cheng
Wed, 21 Oct 2009 09:34:57 +0000

The two batch files shown above are conceptual. For my testing, I actually used "Prototype.bat" and "Test.bat". "Prototype.bat" calls "Test.bat" with "command /c".

When I tried to implement the solution using "Launcher.bat" and "Execution.bat", I kept getting the "Bad command or file name" error message.

Based on further testing, I found that "command" can't accept file names greater than eight characters. It executes names like "Test.bat", "hello.bat", and "electric.bat" just fine. But it chokes if it tries to execute file names like "Execution.bat" or "helloworld.bat".

Chieh Cheng
Wed, 21 Oct 2009 22:55:03 +0000

It seems that changing directory is only a problem if you execute batch files with the ".bat" extension. If you execute batch files with the ".cmd" extension, you won't have this problem. Possibly a different command processor (command.com vs. cmd.exe) is used.

Also, the short file name problem is only a problem for command.com (16-bit command processor). It's not a problem for cmd.exe (32-bit command processor).

Chieh Cheng
Fri, 23 Oct 2009 17:55:44 +0000

Add Comment | Related Links | TrackBack
Related Content

Did your message disappear? Read the Forums FAQ.

Add Comment

Spam Control | * indicates required field
Your Name: *
E-mail:
Remember Me!
Comment: *
File attachment is optional. Please do not attach a file to your submission unless it is relevent.
Attach File:
(20 MB Max)
Spam Protection: * Answer of 8 + 10?
Click button only once, please!

TrackBack

TrackBack only accepted from WebSite-X Suite web sites. Do not submit TrackBacks from other sites.

Send Ping | TrackBack URL | Spam Control

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.

Products | Services
Forums | Latest | RSS
Library | Search | Wiki
Help | Licenses

Login | Register

58 Users Online

Hacking Digital Cameras
Fun for Photographers



Amazon Associate

Copyright © 1996 - 2024. All Rights Reserved.