@filewrite oddity (to me)

Jun 3, 2008
106
1
Temecula, CA
If I have the command in a .btm file

echo %@filewrite[%h,%line]> nul

it does exactly what I want it to do - to write the value of %line into the file opened by handle %h, and I see nothing in my tcc window. However, if %line is empty, it (properly) writes a blank line in my file, but in my tcc window, I see, "ECHO is OFF". Shouldn't the redirection to NUL prevent that?
 
May 20, 2008
9,153
58
Syracuse, NY, USA
If I have the command in a .btm file

echo %@filewrite[%h,%line]> nul

it does exactly what I want it to do - to write the value of %line into the file opened by handle %h, and I see nothing in my tcc window. However, if %line is empty, it (properly) writes a blank line in my file, but in my tcc window, I see, "ECHO is OFF". Shouldn't the redirection to NUL prevent that?
It works better with a space before ">". Whether that's as it should be, I don't know.
Code:
v:\> set h=%@fileopen[test.txt,w,t]

v:\> echo %@filewrite[%h,%no_exist]> NUL
ECHO is OFF

v:\> echo %@filewrite[%h,%no_exist] > NUL

v:\>
 
Jun 3, 2008
106
1
Temecula, CA
It works better with a space before ">". Whether that's as it should be, I don't know.
Code:
v:\> set h=%@fileopen[test.txt,w,t]

v:\> echo %@filewrite[%h,%no_exist]> NUL
ECHO is OFF

v:\> echo %@filewrite[%h,%no_exist] > NUL

v:\>
Vince, you get the gold star. I have no idea why that should matter, but I don't really care. :-) Thank you!
 

rconn

Administrator
Staff member
May 14, 2008
10,886
97
WAD, if a bit unexpected at first.

What's happening is that @FILEWRITE is returning the number of characters written to the file. Since %line is empty, TCC wrote an empty string followed by a CR/LF. So the result of @FILEWRITE is "2", and your command now looks like this:

Code:
echo 2> nul
Now, that syntax does *not* write a "2" to NUL, it redirects STDERR to NUL (see the help). So you wind up with an "echo ", which faithfully reports the status of the ECHO flag.

When you add the space before the >, you get "echo 2 > nul", which redirects STDOUT to NUL, and writes "2" to the bit bucket.

Moral of the story - use the correct syntax (whitespace around redirection characters), and you won't be surprised.
 
Jun 3, 2008
106
1
Temecula, CA
Thanks, Rex. I hadn't realized a space around the redirection characters was proper syntax. I guess you can teach an old dog new tricks! :-)