Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

If I want to run the command

md5deep -rb . | find /I ".jpg" | sort > local.md5

and I run it from the command prompt, it shows exactly like how I typed, but when I put it in a .bat file and run that, this is what I see:

md5deep -rb .   | find /I ".jpg"   | sort  1>local.md5

It seems that it inserts tabs before | and it turns > into a 1>. Why? First I thought that it's something to do with the encoding, but the file is just a simple ANSI file.

Does it have anything to do with @@ turning @ inside .bat files?

share|improve this question

2 Answers 2

up vote 3 down vote accepted

It's nothing to worry about. It's just the way the Windows CMD parser outputs the lines when you don't suppress the "trace" output using:

@echo off

or

@commandname

I'm not sure what you're referring to regarding @@ versus @ (except for possibly the above). I don't know of anything special about @@, unless you're confusing it with %% versus % for variable names.

share|improve this answer
    
Sorry, my bad, I was thinking about %% with %. So its nothing to worry about, I can just use the same command as I would on a command line? Thanks! –  zsero Mar 21 '11 at 2:41
    
+1. Indeed, cmd is just clarifying here (especially the 1> part). The statements are identical. –  Joey Mar 21 '11 at 10:00

The 1> refers to how standard out is being redirected within the bat file.

You have two channels, one for standard out (1>), and one for standard error out (2>). They use either 1> or 2> for processing, and provide two different types of execution feedback. I have this list for different redirection permutations:

command > file      Write standard output of command to file
command 1> file     Write standard output of command to file (same as previous)
command 2> file     Write standard error of command to file (OS/2 and NT)
command > file 2>&1     Write both standard output and standard error of command to file (OS/2 and NT)
command >> file     Append standard output of command to file
command 1>> file    Append standard output of command to file (same as previous)
command 2>> file    Append standard error of command to file (OS/2 and NT)
command >> file 2>&1    Append both standard output and standard error of command to file (OS/2 and NT)
commandA | commandB     Redirect standard output of commandA to standard input of commandB
commandA 2>&1 | commandB    Redirect standard output and standard error of commandA to standard input of commandB (OS/2 and NT)
command < file  command gets standard input from file
command 2>&1    command's standard error is redirected to standard output (OS/2 and NT)
command 1>&2    command's standard output is redirected to standard error (OS/2 and NT)

This is from Rob van der Woude's excellent web site on Win32 scripting: http://www.robvanderwoude.com/redirection.php

Rob

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.