Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!

@filewrite oddity (to me)

Jun
137
3
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?
 
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:\>
 
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!
 
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.
 
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! :-)
 

Similar threads

Back
Top