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!

Trying to pass a string with spaces to a batch file

807569Jul 4 2006 — edited Jul 5 2006
Hi All, I am going nuts here! I am trying to run a batch file (for simplicity lets call us hello.bat, which echos the parameter I pass). I am using Runtime.exec and it works fine with the paramater is no space but it fails when I pass a parameter with a space, here is my code:
cmd[0] = "cmd.exe";
cmd[1] = "/C" ;
cmd[2]="\"C:\\Documents and Settings\\user\\Desktop\\itsutils\\build\\hello.bat\"";
cmd[3] = "\"Hello there\"";
Runtime rt = Runtime.getRuntime()
 Process proc = rt.exec(cmd);

//Input stream handler code here...omitted for clarity.
The string parameters to exec are:
cmd.exe /C "C:\Documents and Settings\user\Desktop\itsutils\build\hello.bat" "Hello There"

I get the following output: ERROR>'C:\Documents' is not recognized as an internal or external command,
ERROR>operable program or batch file.
Process exitValue: 1

Can anyone help me out here...is there something fundamental I am missing?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 2 2006
Added on Jul 4 2006
16 comments
1,532 views