Page 1 of 1
Echo not working on lines which got 0 at end of line
Posted: 28 Jun 2014 04:39
by mohdfraz
Hi,
When I run this below code Middle line is not Echo. any line which got 0 at the end creating issue. I have many files and on them all the lines which get 0 at the end does not get Echo from batch file. Any suggestions what to fix this issue?
Code: Select all
Echo Started>Test.txt
Echo REPEAT : 3 : 0 : 0 : Enter the number of iterations: : 0 : 0>>Test.txt
Echo Finished>>Test.txt
Currently I am doing work around.
Run the code like this
Code: Select all
Echo Started>Test.txt
Echo REPEAT : 3 : 0 : 0 : Enter the number of iterations: : 0 : *0>>Test.txt
Echo Finished>>Test.txt
once files are generated then i use TextCrawler for find and replace command. But Echo should work. Why it is not working? Any idea?
I am using windows xp
Thanks
Re: Echo not working on lines which got 0 at end of line
Posted: 28 Jun 2014 04:47
by npocmaka_
try with:
Code: Select all
Echo REPEAT : 3 : 0 : 0 : Enter the number of iterations: : 0 : 0 1>>Test.txt
What I think is happening here is you're trying to redirect the 0 stream (stdin) to the file.
Setting 1 before the file redirection will redirect the 1 (stdout ) to the file.
Re: Echo not working on lines which got 0 at end of line
Posted: 28 Jun 2014 05:21
by foxidrive
Here are two methods: the first one needs some characters to be escaped with
^ as in
^)Code: Select all
(
Echo Started
Echo REPEAT : 3 : 0 : 0 : Enter the number of iterations: : 0 : 0
Echo Finished
)>Test.txt
Code: Select all
>Test.txt Echo Started
>>Test.txt Echo REPEAT : 3 : 0 : 0 : Enter the number of iterations: : 0 : 0
>>Test.txt Echo Finished
Re: Echo not working on lines which got 0 at end of line
Posted: 29 Jun 2014 08:50
by mohdfraz
npocmaka_ wrote:try with:
Code: Select all
Echo REPEAT : 3 : 0 : 0 : Enter the number of iterations: : 0 : 0 1>>Test.txt
What I think is happening here is you're trying to redirect the 0 stream (stdin) to the file.
Setting 1 before the file redirection will redirect the 1 (stdout ) to the file.
npocmaka_
Thank you...........
foxidrive wrote:Here are two methods: the first one needs some characters to be escaped with
^ as in
^)Code: Select all
(
Echo Started
Echo REPEAT : 3 : 0 : 0 : Enter the number of iterations: : 0 : 0
Echo Finished
)>Test.txt
Code: Select all
>Test.txt Echo Started
>>Test.txt Echo REPEAT : 3 : 0 : 0 : Enter the number of iterations: : 0 : 0
>>Test.txt Echo Finished
foxidrive
Thank you..........
I have also figure out a solution, I added a Space between "0" and ">" and it worked.
Code: Select all
Echo Started>Test.txt
Echo REPEAT : 3 : 0 : 0 : Enter the number of iterations: : 0 : 0 >>Test.txt
Echo Finished>>Test.txt
Thanks
Re: Echo not working on lines which got 0 at end of line
Posted: 29 Jun 2014 13:50
by foxidrive
mohdfraz wrote:I have also figure out a solution, I added a Space between "0" and ">" and it worked.
Code: Select all
Echo Started>Test.txt
Echo REPEAT : 3 : 0 : 0 : Enter the number of iterations: : 0 : 0 >>Test.txt
Echo Finished>>Test.txt
As a programmer you will soon realise that adding whitespace to the end of a line is not a good way to process files simply to get around this redirection issue.
Text in CSV files, and INI files can all be broken by adding whitespace when the program reading the files doesn't expect it.
Re: Echo not working on lines which got 0 at end of line
Posted: 30 Jun 2014 03:54
by mohdfraz
foxidrive wrote:As a programmer you will soon realise that adding whitespace to the end of a line is not a good way to process files simply to get around this redirection issue.
Text in CSV files, and INI files can all be broken by adding whitespace when the program reading the files doesn't expect it.
Agreed,,,,,, Thats why I was trying to avoid space but Its just an way around for my this issue only. But I think I will use your bracket tip, that is much better and secure way to avoid any confusions.
Thank you.
Re: Echo not working on lines which got 0 at end of line
Posted: 30 Jun 2014 04:37
by miskox
Sometimes it is better to do it like this:
Code: Select all
>>test.txt (Echo REPEAT : 3 : 0 : 0 : Enter the number of iterations: : 0 : 0)
Saso