1.

Solve : clipping digit from write appending to logfile?

Answer»

This is probably easy to explain, but my google search hasn't given me a reason why digits are clipped when executing for example below and the 1 is not WRITTEN to file unless there is a space between the 1 and the >> write appending to log file.

REM This example clips the 1
@echo. Write this to file 1>>Log.log

REM This example WRITES the 1
@echo. Write this to file 1 >>Log1.log

Was this a question?
You have shown that there has to a space before the redirection thing. Otherwise the last char gets clipped.

Why?
Because.

Sp from now on it with be call DaveLembke's rule. Quote from: DaveLembke on May 22, 2011, 07:09:51 PM

This is probably easy to explain, but my google search hasn't given me a reason why digits are clipped when executing for example below and the 1 is not written to file unless there is a space between the 1 and the >> write appending to log file.

REM This example clips the 1
@echo. Write this to file 1>>Log.log

REM This example writes the 1
@echo. Write this to file 1 >>Log1.log

It's because of numbered console streams.




lol....Geek-9pm


Thanks Salmon for pointing out the correct terminology of Numbered Console Streams! Now I understand what it is instead of just saying..."well you have to add a space...why I dont really know ....other than if I dont, it clips digits... so just add the space."

I wasnt satisfied with just knowing that adding a space makes it work correctly ( without knowing exactly why ) vs without a space clipped the digit, while it wouldnt bother text that is bound tight to it. I am the type of person who likes to understand "why" something behaves the way that it does ......Instead of being satisfied with "well it does it and who cares as to why and how, ...it works so just use it! "

Given the correct terminology I was able to then find more info that helps me understand this:

Stream Redirection:

The explanations regarding the less and greater than symbols aren't complete without knowing what goes where and how to manipulate them.

Handles:
0 - Standard input(normally keyboard but can be redirected from file)

1 - Standard output(Normally console but can be redirected)

2 - Standard error(Normally console but can be redirected)

3 - 9 - Undefined but semi usable, basically useless - at least in BATCH scripts.


Above we were implicitly redirecting, the less than SYMBOL implies that file contents will be sent to the standard input and the greater than symbols implies that the standard output will be sent to file.

To explicitly redirect the number of the handle must come IMMEDIATELY before the redirection symbol, no spaces allowed. This is essentially the same script as above:



echo on

1> example.txt echo echo hello
1>> example.txt echo exit
cmd 0< example.txt
del example.txt
pause

As found at: http://judago.webs.com/batchoperators.htm




Discussion

No Comment Found