Echo not working on lines which got 0 at end of line

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
mohdfraz
Posts: 69
Joined: 29 Jun 2011 11:16

Echo not working on lines which got 0 at end of line

#1 Post by mohdfraz » 28 Jun 2014 04:39

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

npocmaka_
Posts: 512
Joined: 24 Jun 2013 17:10
Location: Bulgaria
Contact:

Re: Echo not working on lines which got 0 at end of line

#2 Post by npocmaka_ » 28 Jun 2014 04:47

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.

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Echo not working on lines which got 0 at end of line

#3 Post by foxidrive » 28 Jun 2014 05:21

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

mohdfraz
Posts: 69
Joined: 29 Jun 2011 11:16

Re: Echo not working on lines which got 0 at end of line

#4 Post by mohdfraz » 29 Jun 2014 08:50

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

foxidrive
Expert
Posts: 6031
Joined: 10 Feb 2012 02:20

Re: Echo not working on lines which got 0 at end of line

#5 Post by foxidrive » 29 Jun 2014 13:50

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.

mohdfraz
Posts: 69
Joined: 29 Jun 2011 11:16

Re: Echo not working on lines which got 0 at end of line

#6 Post by mohdfraz » 30 Jun 2014 03:54

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.

miskox
Posts: 556
Joined: 28 Jun 2010 03:46

Re: Echo not working on lines which got 0 at end of line

#7 Post by miskox » 30 Jun 2014 04:37

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

Post Reply