Jump to content



Photo

Run multiple DOS commands in one line


  • Please log in to reply
6 replies to this topic

#1 trids

trids

    Hmmm .. and what have we here?

  • Active Members
  • PipPipPipPipPipPip
  • 1,004 posts

Posted 10 October 2007 - 11:33 AM

I just stumbled across this sublime technique of concatenating DOS commands with &&, in order to run them on the same line.

EXAMPLE -- Does all of this in ONE execution of RunWait().. :)
  • set current drive to C:
  • change path to WINNT folder
  • collect the list of files there into a temporary file
  • open the file in your text editor
    RunWait( @COMSPEC & " /c C:&&cd \winnt&&dir>D:\temp\multi.txt&&D:\temp\multi.txt", "", @SW_SHOW )






#2 BrettF

BrettF

    My Drunk Monkey Guerilla is gonna getcha!

  • MVPs
  • 7,662 posts

Posted 10 October 2007 - 11:37 AM

Pure awesomeness :)

#3 lordofthestrings

lordofthestrings

    Prodigy

  • Active Members
  • PipPipPip
  • 191 posts

Posted 10 October 2007 - 12:19 PM

in dos what this does is the following:

Command A & Command B --> execute command A, then execute command B. (no evaluation of nothing)
Command A | command B --> execute command A, and redirect all it's output into the input of command B.
Command A && Command B ---> means execute command A, Evaluate the errorlevel after running Command A, and if the exit code (errorlevel) is 0, only then execute command B.
Command A || command B ---> execute Command A, evalutate the exit code of this command and if it's anything but 0, Only then execute command B.
command A >> outputfile.txt 2>&1 ---> means execute command A, and write the STDERR Output to STDOUT
examples:
dir c:\ & echo All done!
help | more
or
type c:\windows\system32\drivers\etc\hosts | find /I "Microsoft"
dir c:\windows || echo I can't find this directory c:\windows
dir>c:\file.txt 1<&2 (explain me why you see the dir command send it's output to the dosbox, while I clearly specify that I should output it to c:\file.txt......


if you want to read more about this look use command redirection operators

http://www.microsoft.com/resources/documen...n.mspx?mfr=true


--reason edit-- More examples of all commands :)

Edited by lordofthestrings, 10 October 2007 - 12:26 PM.


#4 trids

trids

    Hmmm .. and what have we here?

  • Active Members
  • PipPipPipPipPipPip
  • 1,004 posts

Posted 10 October 2007 - 01:21 PM

Great! Thanks, lots, it's nice to have the whole picture :)

#5 drtrobridge

drtrobridge

    Seeker

  • New Members
  • 1 posts

Posted 13 May 2013 - 03:36 PM

I just stumbled across this sublime technique of concatenating DOS commands with &&, in order to run them on the same line.

EXAMPLE -- Does all of this in ONE execution of RunWait().. :)

  • set current drive to C:
  • change path to WINNT folder
  • collect the list of files there into a temporary file
  • open the file in your text editor
    RunWait( @COMSPEC & " /c C:&&cd \winnt&&dir>D:\temp\multi.txt&&D:\temp\multi.txt", "", @SW_SHOW )

 

I had to create and account to let you know that this info just turned my project from a disaster to a success. Thank you for your help!! This forum is spectacular.



#6 TheSaint

TheSaint

    *** Knight Templar ***

  • MVPs
  • 3,988 posts

Posted 13 May 2013 - 07:43 PM

Great find, thanks for sharing.


Make sure brain is in gear before opening mouth!Ignoring those who try to divert conversation with irrelevancies.If I put effort into communication, I expect you to read properly & fully, or just not comment.If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.I'm only big and bad, to those who have an over-active imagination.I may have the Artistic Liesense to disagree with you.TheSaint's Toolbox

#7 spudw2k

spudw2k

    i dunno what i'm doing

  • Active Members
  • PipPipPipPipPipPip
  • 1,147 posts

Posted 14 May 2013 - 05:00 PM

loves me some &&.  I use it quite often






4 user(s) are reading this topic

0 members, 4 guests, 0 anonymous users