Using "new line" in batch file for command

P

Peter Rossiter

I want to open a DOS window (in WinXP) and then run a single long
DOS command from a batch file.

The batch file containing the long command looks messay and is hard
for me to tweak quickly. How can I alter the layout of this long
command in the batch file to make it more readable?

Ideally I would like to have different parts of it (command name,
sart file name, end file name, etc) on separate lines. Is there a
way I can put these parts each on a new line but have the whole
thing recognised as a single command?
 
T

Ted Davis

I want to open a DOS window (in WinXP) and then run a single long
DOS command from a batch file.

The batch file containing the long command looks messay and is hard
for me to tweak quickly. How can I alter the layout of this long
command in the batch file to make it more readable?

Ideally I would like to have different parts of it (command name,
sart file name, end file name, etc) on separate lines. Is there a
way I can put these parts each on a new line but have the whole
thing recognised as a single command?

for %%A in (foo) do ( stuff
more stuff %%A
extra stuff)


T.E.D. ([email protected])
SPAM filter: Messages to this address *must* contain "T.E.D."
somewhere in the body or they will be automatically rejected.
 
R

Richard Bonner

Peter said:
I want to open a DOS window (in WinXP) and then run a single long
DOS command from a batch file.
The batch file containing the long command looks messay and is hard
for me to tweak quickly. How can I alter the layout of this long
command in the batch file to make it more readable?
(Snip)

*** T.E.D. has given a suggestion already, but I must add that you can
make batch files more readable by using spacing. For
instance:

IF "%1"=="TEST" GOTO TEST
IF NOT "%1"=="TEST" GOTO END
:TEST
ECHO TEST>TEST.TXT
:END

Can be:

IF "%1" == "TEST" GOTO TEST
IF NOT "%1" == "TEST" GOTO END

:TEST
ECHO TEST > TEST.TXT

:END

Richard Bonner
http://www.chebucto.ns.ca/~ak621/DOS/
 
H

Herbert Kleebauer

Peter said:
I want to open a DOS window (in WinXP) and then run a single long
DOS command from a batch file.

The batch file containing the long command looks messay and is hard
for me to tweak quickly. How can I alter the layout of this long
command in the batch file to make it more readable?

Ideally I would like to have different parts of it (command name,
sart file name, end file name, etc) on separate lines. Is there a
way I can put these parts each on a new line but have the whole
thing recognised as a single command?

setlocal
set command_name=c:\programfiles\abc\def\xy.exe
set options=-a -b +c -d
set parameter=infile.txt outfile.txt

%command_name% %options% %parameter%
 
K

Kenneth Brody

Ted Davis wrote:
[...]
for %%A in (foo) do ( stuff
more stuff %%A
extra stuff)

This tries to execute "( stuff" on my Win98 system and, of course, I
get "bad command or filename" as there is no "(" command.

Perhaps this works on an NT class system, but not a 9x system, and
certainly not under MS-DOS itself.

In fact, my XP system doesn't like this, either. While it will execute
each line for every "for" item, they are distinct commands, not a single
command wrapped to multiple lines, as the OP was asking about.

He is asking for the equivalent of the "\" line continuation available
under *nix, as in:

/path/to/executable \
-flag1 -flag2 -flag3 \
filename

which is equivalent to:

/path/to/executable -flag1 -flag2 -flag3 filename

This is definitely not available under MS-DOS. Whether it is available
under NT/2000/XP/2003 at the command prompt is a different question, for
which I do not know the answer.
 
C

Charles Dye

Kenneth Brody said:
[ Original poster: ]
Ideally I would like to have different parts of it (command name,
sart file name, end file name, etc) on separate lines. Is there a
way I can put these parts each on a new line but have the whole
thing recognised as a single command?
He is asking for the equivalent of the "\" line continuation available
under *nix, as in:

/path/to/executable \
-flag1 -flag2 -flag3 \
filename

which is equivalent to:

/path/to/executable -flag1 -flag2 -flag3 filename

This is definitely not available under MS-DOS. Whether it is available
under NT/2000/XP/2003 at the command prompt is a different question, for
which I do not know the answer.

I believe most versions of CMD.EXE allow the escape character ^ to be
used in this capacity. Certainly 4NT does.

c:\path\to\executable ^
/flag1 /flag2 /flag3 ^
filename

4DOS also supports this kind of construct, though the default escape
character differs. So it is available under MS-DOS, Windows 98, etc.
provided you aren't locked into MS's toy shells. (I think the OP
was asking about CMD.EXE of Windows XP, and his "DOS" was just an
unfortunate misnomer for CLI.)
 
T

Ted Davis

Ted Davis wrote:
[...]
for %%A in (foo) do ( stuff
more stuff %%A
extra stuff)

This tries to execute "( stuff" on my Win98 system and, of course, I
get "bad command or filename" as there is no "(" command.

Perhaps this works on an NT class system, but not a 9x system, and
certainly not under MS-DOS itself.

In fact, my XP system doesn't like this, either. While it will execute
each line for every "for" item, they are distinct commands, not a single
command wrapped to multiple lines, as the OP was asking about.

He is asking for the equivalent of the "\" line continuation available
under *nix, as in:

/path/to/executable \
-flag1 -flag2 -flag3 \
filename

which is equivalent to:

/path/to/executable -flag1 -flag2 -flag3 filename

This is definitely not available under MS-DOS. Whether it is available
under NT/2000/XP/2003 at the command prompt is a different question, for
which I do not know the answer.

Why are you talking about those OSs - the question was about Win XP's
batch language? And of course, you have to replace the place holders
with real code.



T.E.D. ([email protected])
SPAM filter: Messages to this address *must* contain "T.E.D."
somewhere in the body or they will be automatically rejected.
 
K

Kenneth Brody

Ted Davis wrote:
[...]
Why are you talking about those OSs - the question was about Win XP's
batch language? And of course, you have to replace the place holders
with real code.

Because I missed the words "in XP" statement in his original post,
and I am reading this in the "comp.os.msdos.programmer" newsgroup.
He also crossposted to "comp.os.msdos.misc" and "alt.msdos". None
of these have to do with a command window under XP.
 
T

Ted Davis

Ted Davis wrote:
[...]
Why are you talking about those OSs - the question was about Win XP's
batch language? And of course, you have to replace the place holders
with real code.

Because I missed the words "in XP" statement in his original post,
and I am reading this in the "comp.os.msdos.programmer" newsgroup.
He also crossposted to "comp.os.msdos.misc" and "alt.msdos". None
of these have to do with a command window under XP.

True enough, but I long ago learned that hardly anyone - except hard
core DOS programmers - knows/cares that there *is* an important
difference, so I look for clues. If I can't find a clue and it makes
a difference, I usually ask. True DOS people usually give the version
(they know it's likely to make a difference) or at least say something
that indicates they aren't using Windows.


T.E.D. ([email protected] - e-mail must contain "T.E.D." or my .sig in the body)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top