Multiple commands per line

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
tkhanipov
Posts: 1
Joined: 29 Jul 2008 09:56
Location: Moscow, Russia

Multiple commands per line

#1 Post by tkhanipov » 29 Jul 2008 10:02

Hello!

Could you please tell me how to call several commands in one line?
For example, I want to have a single line which will act as the sequence:

echo Bla-bla-bla! Let us call dir?
dir
echo More-bla-bla-bla!

I have no idea of implementing this. Is it possible?

Thanks a lot! It's a very nice and useful site.

Odder93
Posts: 11
Joined: 15 Jul 2008 12:43
Contact:

#2 Post by Odder93 » 29 Jul 2008 11:31

EDIT: I can't get example 2 working, but maybe someone know how it works :p

in batch files and in CMD you can use:

Code: Select all

(
<command1>
<command2>
<command3>
<etc.>
)


This will operate each command at nearly same time and output will be showed line by line :-)

in CMD you can also use (If you are lucky it also works in batch files):

Code: Select all

^
<command1>^
<command2>^
<command3>^
<etc>^
<last command>


This will do the same as "(" ")" but will show output on ONE line instead :-D

example 1:

Code: Select all

(
echo blah blah blah... let's jump to root
cd ..
echo blah blah blah...
)


example 2:

Code: Select all

^
echo blah blah blah... let's jump to root^
cd ..^
echo blah blah blah...


Have fun!

Best regards
Odder

gallennc
Posts: 1
Joined: 30 Jul 2008 21:14

#3 Post by gallennc » 30 Jul 2008 21:20

If you want to execute this on one line:

echo Bla-bla-bla! Let us call dir?
dir
echo More-bla-bla-bla!

shouldn't it be as simple as:

echo Bla-bla-bla! Let us call dir? & dir & echo More-bla-bla-bla!

works for me. :)

Odder93
Posts: 11
Joined: 15 Jul 2008 12:43
Contact:

#4 Post by Odder93 » 31 Jul 2008 03:32

gallennc wrote:If you want to execute this on one line:

echo Bla-bla-bla! Let us call dir?
dir
echo More-bla-bla-bla!

shouldn't it be as simple as:

echo Bla-bla-bla! Let us call dir? & dir & echo More-bla-bla-bla!

works for me. :)



ohh, that way ;-)

I have read you should use "&" twice, as:

Code: Select all

echo Bla-bla-bla! Let us call dir? && dir && echo More-bla-bla-bla!


But it might work both ways
:shock:

DGMakers
Posts: 13
Joined: 30 Jun 2008 04:28

re

#5 Post by DGMakers » 31 Jul 2008 07:46

you can use single & symbols in if's eg:

Code: Select all

if '%var%'=='this' echo lalala & echo Still in the if !!! & echo omg still in there, i think? i think there may be a limit of and symbols but yea & pause & exit

greenfinch
Posts: 36
Joined: 17 Jul 2008 07:37

#6 Post by greenfinch » 17 Aug 2008 18:45

See http://technet.microsoft.com/en-us/libr ... 37438.aspx

&& means 'do the next one if the last one completed OK'

Post Reply