Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Problem using Runtime.getRuntime().exec(cmd) with windows path containing &

807603Jan 30 2008 — edited Jan 31 2008
Currently I use Runtime.getRuntime().exec(command) to effectively invoke a file on windows XP. For instance the command might be:

cmd.exe /C "C:\Documents and Settings\John\My Documents\dir\file.doc"

and this starts up word with the file loaded in the application.

However, if the path contains an & character the exec() fails. For instance:

cmd.exe /C "C:\Documents and Settings\John\My Documents\a & b\file.doc"

Though the directory "a & b" exists and so does file.doc within that directory as shown by windows explorer.

Obviously that & coupled with the way I am presenting the command to exec() is causing a problem. Do I need to be escaping that & character somehow and if so how. Any ideas?

Help would be very much appreciated.

All the best.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 28 2008
Added on Jan 30 2008
6 comments
1,103 views