Problem using Runtime.getRuntime().exec(cmd) with windows path containing &
807603Jan 30 2008 — edited Jan 31 2008Currently 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.