line continuation in Window XP CLI (cmd.exe)

allelopath
allelopath used Ask the Experts™
on
I'm trying to create a batch file to execute a java program. The command is long due to the program arguments. I read that ^ is the line continuation for a batch file, but that doesn't work:

java -jar sall.jar ^
argument1 ^
argument2 ^
argument3 ^
argument4

What can I do?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2007

Commented:
That was my understanding of line continuation as well. Does this batch file run?

@echo off

dir ^
/ad ^
c:\temp

Are any syntax errors generated when you run your processing? I guess I'm trying to ask why you think it doesn't work.
Commented:
One thing to add to that.  The last time I used the feature it confused the hell out of me why it wasn't working until I realised there was a space after one of the ^ characters.  Worth checking as if there is anything else on the line it won't work..... that shows up as the commands being interpreted as seperate lines then though, i.e. trying to execute /ad or c:\temp

Steve

Author

Commented:
Here is output of your test:
Did it work?

 Volume in drive C has no label.
 Volume Serial Number is 51DC-0FA0

 Directory of c:\

File Not Found

11/26 Forrester Webinar: Savings for Enterprise

How can your organization benefit from savings just by replacing your legacy backup solutions with Acronis' #CyberProtection? Join Forrester's Joe Branca and Ryan Davis from Acronis live as they explain how you can too.

Author

Commented:
dragon:
I checked at your behest, but no spaces after the ^


The first argument is accepted. The error i get is:

argument2
 is not recognized as an internal or external command,
operable program or batch file.
argument3
 is not recognized as an internal or external command,
operable program or batch file.
argument4
 is not recognized as an internal or external command,
operable program or batch file.

Commented:
Can you specify what the actual commands you are putting in are... perhaps there is something in there that is causing it to stop the line.  I presume we are just talking paths/filenames here?

Clearly the problem also is with the argument1 line and/or the ^ on the end of that line.

Steve

Commented:
BTW copying and pasting your example version works for me... with the addtion of echo so I can not have to run java:

echo java -jar sall.jar ^
argument1 ^
argument2 ^
argument3 ^
argument4

returns

C:\>echo java -jar sall.jar argument1 argument2 argument3 argument4
java -jar sall.jar argument1 argument2 argument3 argument4

Steve

Author

Commented:
>>I presume we are just talking paths/filenames here
Yes, an argument is something like:
"C:\some\directory with\ spaces in the name\"

Author

Commented:
oops, argument is something like:
"C:\some\directory with\ spaces in the name"
(no \ at the end)

Author

Commented:
tried these, but no difference:
"C:\\some\\directory with\\ spaces in the name"
"C:/some/directory with/ spaces in the name"
Commented:
Ahh OK.  It is the " that are the problem.  if a line starts with a " then it doesn't work with the continuation thing.  What I have normally done here is added a space before the " on the argument lines.  This adds a second space inbetween arguments on the command line which doesn't normally matter.

SteveGTR, have you come across any other way of doing this, have generally added a space by habit when I;ve used quotes and never bothered to find out if there is 'correct' way.

Steve
Top Expert 2007

Commented:
Can you post the exact command that is giving you problems? Also, can you post any error messages that are reported?

Commented:
Steve while we wait for allelopath what I get is

java -jar sall.jar ^
 "C:\some\directory with\ spaces in the name" ^
"C:\some\directory with\ spaces in the name" ^
"C:\some\directory with\ spaces in the name"

Would append the first argument to the java line then try then execute the last two lines as another command.  if the first character on a line is a " then it seems to stop it working as a continuation so I always add a space before the " if quotes are needed.  For some wacky reason though the space isn't needed on the last line, even if there is a quote at the beginning of the line.

I've never come across any docs that shows this facility, I stumbled across it in a pre-written batch file ages ago and have used it now and again.  Do you have any docs that show how it's supposed to work?

Steve
Top Expert 2007

Commented:
Well isn't that interesting. I found that this worked:

java -jar sall.jar ^
"1^" ^
"2^" ^
"3^"

Commented:
Odd isn't it, hadn't tried your combination but at least thats two workarounds then hopefully for him now anyway :-)

Steve
Top Expert 2007

Commented:
I missed your work around. What was it?
Commented:
Add a space at the beginning of the lines that start with a "
Top Expert 2007

Commented:
And that allows all the lines to be treated as one?

Commented:
Always has for me, odd eh!
e.g.

echo java -jar sall.jar ^
 "argument 1" ^
 "argument 2" ^
 "argument 3" ^
"argument 4"

ends up running

C:\>echo java -jar sall.jar  "argument 1"  "argument 2"  "argument 3" "argument 4"
java -jar sall.jar  "argument 1"  "argument 2"  "argument 3" "argument 4"

Steve
Top Expert 2007

Commented:
Yes, I see. That is another solution. It wasn't clear to me in your last posted whether this worked for all the arguments :)
Top Expert 2007

Commented:
And you can get rid of the extra spaces like this:

echo Multiple lines with quoteed parameters^
 "1"^
 "2"^
 "3"

Commented:
Good point, never thought of that....
Wonder if alleopath is still with us :-)

Steve
Top Expert 2007

Commented:
Excellent split <--- sarcasm intended. You made the list allelopath, good luck on your future questions...

Commented:
Yes allelopath, choice is yours of course but if you have a couple of solutions given, disappear and don't give any feedback it's courteous to at least split the points between the people helping...

thanks for the points to me anyway.

Steve

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial