Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Very long cmd-line

193 views
Skip to first unread message

Markus Eymann

unread,
Jun 19, 2002, 3:09:37 AM6/19/02
to
hi,

is it possible to split one long command-line into 2 or more lines, and if
so how?

thank's a lot
markus


Timo Salmi

unread,
Jun 19, 2002, 4:50:01 AM6/19/02
to
In article <3d10299c$1...@news.bluewin.ch>,

Markus Eymann <eym...@bluewin.ch> wrote:
> is it possible to split one long command-line into 2 or more lines, and if
> so how?

In MS-DOS, no. You'll have to figure out the command so that the
logic can be spread over several lines.

All the best, Timo

--
Prof. Timo Salmi ftp & http://garbo.uwasa.fi/ archives 193.166.120.5
Department of Accounting and Business Finance ; University of Vaasa
mailto:t...@uwasa.fi <http://www.uwasa.fi/~ts/> ; FIN-65101, Finland
Useful batch files and tricks ftp://garbo.uwasa.fi/pc/link/tsbat.zip

William Allen

unread,
Jun 19, 2002, 5:39:15 AM6/19/02
to
"Markus Eymann" wrote in message

> is it possible to split one long command-line into 2 or more lines, and if
> so how?

In Windows 95/98/ME there isn't a standard line continuation
character, but there are two approaches you could consider
if it's really necessary to split lines.

(a) Use Environment variables

You can either load several parts of the line into several variables,
or build up the line in one variable. Obviously, you need plenty
of environment space allocated. This demo opens a child shell
with 4096 bytes of environment and builds up one long line
in stages:

====Begin cut-and-paste (omit this line)
@ECHO OFF
IF (GOTO:)==(%1) %1%2 (Subroutine Handler)

%COMSPEC%/e:4096/c %0 GOTO: _MAIN

GOTO EOF (=Subroutine section below=)
:_MAIN (Usage: %COMSPEC%/e:4096/c %0 GOTO: _MAIN)

:: Load the line into a variable
SET LN=ECHO. A beginning is a very delicate time. Know, then,
SET LN=%LN% that it is the year 10191. The known universe is ruled
SET LN=%LN% by the Padishah Emperor Shaddam IV, my father. In this
SET LN=%LN% time, the most precious substance in the universe is the
SET LN=%LN% spice melange. The spice extends life. The spice ...
SET LN=%LN% expands consciousness. The spice is vital to space travel.

:: Expand the LN variable, which executes the entire ECHO line
%LN%

:EOF (End-of-file)

====End cut-and-paste (omit this line)
Win9x GUI study/demo only. Cut-and-paste as Batch script (file with .BAT
extension). Lines that don't begin with 2 spaces have wrapped by mistake.
If editing or mixing with your own code, see Subroutine Guidelines below.

============Screen capture Windows 95
C:\WORK>demo1
A beginning is a very delicate time. Know, then, that it is the year 10191. Th
known universe is ruled by the Padishah Emperor Shaddam IV, my father. In this
time, the most precious substance in the universe is the spice melange. The spi
e extends life. The spice ... expands consciousness. The spice is vital to spac
travel.
C:\WORK>
============End screen capture

(b) Use the continuation construct %[LineFeed]%

Here, [LineFeed] means the LineFeed character, the ASCII
character with value 10 which some editors can insert directly
into the text of a Batch file. The [LineFeed] is a valid name
for a variable, but won't normally be used, so its expansion,
%[LineFeed]% will be empty. However, many editors display
the enclosed [LineFeed] as a full line break, so a line containing
appears properly broken into continue lines, but is executed as
a single line. You can insert a LineFeed in say EDIT.COM by
pressing [Ctrl-P] then [Ctrl-J].

The following DEMO2.BAT is such a batch file with only two
executable lines (the first being @ECHO OFF):

====Capture of Batch file DEMO2.BAT as displayed in EDIT.COM
@ECHO OFF
ECHO. A beginning is a very delicate time. Know, then,%
% that it is the year 10191. The known universe is%
% ruled by the Padishah Emperor Shaddam IV, my father.%
% In this time, the most precious substance in the%
% universe is the spice melange. The spice extends life.%
% The spice ... expands consciousness. The spice%
% is vital to space travel.

====End Capture
Notice that the %[LineFeed]% constructs display as %line-ends
followed by a newline beginning with the second %

============Screen capture Windows 95
C:\WORK>demo2.bat
A beginning is a very delicate time. Know, then, that it is the year 10191. The
known universe is ruled by the Padishah Emperor Shaddam IV, my father. In this
time, the most precious substance in the universe is the spice melange. The spic
e extends life. The spice ... expands consciousness. The spice is vital to space
travel.
C:\WORK>
============End screen capture

Note that embedding characters outside the normal printable range,
such as a [LineFeed] is not good practice, since it some editors
alter them to Carriage-Return+LineFeed combos, and the resulting
files may not print properly.

--
(pp) William Allen

Note 1
====Batch Subroutines: Guidelines for use

Batch Subroutines are code chunks for inclusion in a main Batch script.
Your main Batch Script itself should BEGIN with our two standard lines:
@ECHO OFF
IF (GOTO:)==(%1) %1%2 (Subroutine Handler)

The "Subroutine Handler" intercepts and routes all Subroutine recalls.

Your main Batch script should keep our Subroutine section at the END
GOTO EOF (=Subroutine Section below=)
... all the lines of code for Subroutine(s) are here ...
:EOF (End-of-file)

The "GOTO EOF" in the Subroutine Section header isolates it properly
from any of your own code if you add it above this Subroutine Section.

Typical Subroutine invocations (with Subroutine PARameters) are:
CALL %0 GOTO: _SUBR Par1 Par2
OR (where a child shell call is required):
%COMSPEC% /c %0 GOTO: _SUBR Par1 Par2

This restarts the main script (%0 holds its recall name). The GOTO: (as
the %1 parameter) is caught by Subroutine Handler at 2nd line of main
script. The Handler uses the Subroutine's ID (%2=_SUBR above) to jump
to right Subroutine (which "sees" Par1 as %3 and Par2 as %4). When the
Subroutine ends, control returns to main script at line after the call.

====Editing/mixing our code with your own code in a Batch file:

KEEP the "Subroutine Handler" line as the second line of your own version
(after the initial @ECHO OFF). The Handler line is needed to route calls
to Subroutines, but won't otherwise affect any of your code. KEEP all
Subroutine code (and the EOF label) at the end of your reworked version.
The "Subroutine code" is all the text including and following the line(s):
GOTO EOF (=Subroutine section below=)

The "GOTO EOF" in this line prevents execution of the following Subroutine
code unless it's specifically invoked by a Subroutine call.

Follow these guidelines and it is easier to combine any of our posted
Subroutines with your own scripts, and maintain the resultant code mix.


William Allen

unread,
Jun 19, 2002, 8:30:02 AM6/19/02
to
"William Allen" wrote in message

> "Markus Eymann" wrote in message
> > is it possible to split one long command-line into 2 or more lines, and if
> > so how?
...snip

> (b) Use the continuation construct %[LineFeed]%
>
> Here, [LineFeed] means the LineFeed character, the ASCII
> character with value 10 which some editors can insert directly
> into the text of a Batch file. The [LineFeed] is a valid name
> for a variable, but won't normally be used, so its expansion,
> %[LineFeed]% will be empty. However, many editors display
> the enclosed [LineFeed] as a full line break, so a line containing
> appears properly broken into continue lines, but is executed as
> a single line. You can insert a LineFeed in say EDIT.COM by
> pressing [Ctrl-P] then [Ctrl-J].

For those interested in using the %[LineFeed]% Line Continuation
construct, this Batch file utility may help. It allows you to use any
Line Continuation character you choose, (set it in the Batch file
utility where shown). The demo, pasted as LINCON.BAT uses the
_ [underscore] character.

Create your Draft Batch File with the _ character as your continuation
character, and then process it with LINCON.BAT to convert these
to the %[LineFeed]% Line Continuation construct. The subsequently
converted Batch file will read with properly continued lines when viewed
in say, the EDIT.COM editor, or TextPad (commercial product) editor,
and the continued lines will execute as one long command line.

====Begin cut-and-paste (omit this line)
@ECHO OFF
IF (GOTO:)==(%1) %1%2 (Subroutine Handler)

IF ()==(%1) GOTO _INSTRUCTIONS
IF NOT EXIST %1 GOTO _INSTRUCTIONS

:: Set your own LineContinuationChar here:
SET LC=_

%COMSPEC%/c %0 GOTO: _LINCON ECHO. %LC%| debug %1>NUL
ECHO. %1 LineContinuations %LC% replaced with %%[LineFeed]%%
SET LC=

GOTO EOF (=Subroutine section below=)

:_LINCON (Usage: %COMSPEC%/c %0 GOTO: _LINCON ECHO. LineConChar)
%3ea0 be 00 01 bf 00 01 a4 80 7c fe '%4' 75 11 80 7c ff
%3eb0 0d 75 0b c6 44 fe 25 c6 44 ff 0a c6 04 25 e2 e6
%3ec0 81 ef 00 01 89 f9 c3
FOR %%C IN (rip a0 g w q) DO %3%%C

GOTO EOF
:_INSTRUCTIONS (for using the script)
ECHO. Syntax: %0 DraftBatchFile.BAT
ECHO. The LineContinuation Characters in DraftBatchFile.BAT
ECHO. are replaced with the line continuation construct
ECHO. %%[LineFeed]%% (overwriting original DraftBatchFile.BAT)

:EOF (End-of-file)

====End cut-and-paste (omit this line)
Win9x GUI study/demo only. Cut-and-paste as Batch script (file with .BAT
extension). Lines that don't begin with 2 spaces have wrapped by mistake.
If editing or mixing with your own code, see Subroutine Guidelines below.

The screen capture shows a draft batch file prepared with _ line
continuations, then processed by the above demo to replace these
with the %[LineFeed]% Line Continuation construct. The second
part the the screen capture shows how the resulting Batch file
appears in EDIT.COM

============Screen capture Windows 95
C:\WORK>type longline.bat
@ECHO OFF
ECHO. A beginning is a very delicate time. Know, then, _
that it is the year 10191. The known universe is ruled _
by the Padishah Emperor Shaddam IV, my father. In this _
time, the most precious substance in the universe is the _
spice melange. The spice extends life. The spice ... _
expands consciousness. The spice is vital to space _
travel.

C:\WORK>lincon.bat LONGLINE.BAT
LONGLINE.BAT LineContinuations _ replaced with %[LineFeed]%
C:\WORK>longline.bat


A beginning is a very delicate time. Know, then, that it is the year 10191. The
known universe is ruled by the Padishah Emperor Shaddam IV, my father. In this
time, the most precious substance in the universe is the spice melange. The spic
e extends life. The spice ... expands consciousness. The spice is vital to space
travel.
C:\WORK>
============End screen capture

============Screen capture of resulting LONGLINE.BAT in EDIT.COM


@ECHO OFF
ECHO. A beginning is a very delicate time. Know, then, %

%that it is the year 10191. The known universe is ruled %
%by the Padishah Emperor Shaddam IV, my father. In this %
%time, the most precious substance in the universe is the %
%spice melange. The spice extends life. The spice ... %
%expands consciousness. The spice is vital to space %
%travel.
============End screen capture

Note that there is a limit of around 1000 characters on command
lines you can use in Windows 95/98/ME Batch files.

William Allen

unread,
Jun 20, 2002, 12:27:34 AM6/20/02
to
"William Allen" wrote in message
...snip (post timed: Wed, 19 Jun 2002 10:39:15 +0100)

For Mike (and other interested lurkers), the Original Poster
replied to my first post by email as follows:

======Email Message starts
Hi william,

seems that this is the way I'm searching for.
Thanks for your help :)

markus
======Email Message ends

(There was no indication which of the two suggested
solutions was used).

--
(pp) William Allen


0 new messages