Flora
Flora

Reputation: 11

Writing a variable with the value 0 into a file (Batch)

i'm trying to write an integer to a file using redirection in batch,but i can't seem to do it.All i get is empty lines.

set var_1=0
echo %var_1%>output.txt

The same happens when i try to write numbers directly without declaring a variable first. although this is not the case when i use two digit numbers or more. Any solution to this?

Already tried

set var_1=100
set /a var_1=0
echo %var_1%>output.txt

Didn't know why i even tried this but i did it and the problem persist.

Thank you in advance.

Update : * I've already found a solution to this after a lot of searching *

For those who are interested to the solution and explaination : http://www.dostips.com/forum/viewtopic.php?f=3&t=4668

Upvotes: 0

Views: 99

Answers (2)

peter
peter

Reputation: 42182

If you try this at the console you see what is going on , you get something like

ECHO is on (aan).

Which means your 0 is neglected because the console sees it as a kind of null. Use this instead, the space does the trick

echo %var_1% > output.txt

Upvotes: 0

Magoo
Magoo

Reputation: 79983

Problem with a digit directly before the redirector.

try

>filename echo 0

1>nul redirects standard output to nul (suppresses output) 2>nul redirects standard error to nul (suppresses error messages)

0 is standard input

3..9 similarly affected, nul can be a filename if desired.

Upvotes: 1

Related Questions