Solved Batch file does not work as expected

September 29, 2012 at 15:36:35
Specs: Windows XP Pro, intel P4 dual core/4gb RAM
Hello .. sorry my brief is so "brief"

My system:
Windows XP Pro - Fully patched with MS updates
Using AVG 2012 FREE and Comodo Firewall

Details of the problem:

I have the following batch file called TEST.bat The following is /Code/

time < enter.key

That is all there is to it.
"enter.key" is a text file with two carriage return/Line feeds in it.

when I run the batch file TEST.bat this is what actually get processed:

time 0<enter.key

IE. For some reason the command line from the batch file is changed and when it is run a space a a ZERO are inserted before the less-than < sign.

I have searched high and low for a sensible explaination and possible fix but my search has been fruitless.

It may well be that, infact, I have a virus .. and so I do not know where I should post this on your website.

Please help.
Please do not spam/flame etc ..

See More: Batch file does not work as expected

Report •

September 29, 2012 at 15:54:59
✔ Best Answer
This is normal operation. You're redirecting stream 0, aka STDIN. CMD's just making it explicit.

How To Ask Questions The Smart Way

Report •

September 29, 2012 at 16:41:16
Thanks for your reply

this has never happened before using windows .. it is also interfereing with the actual function of executables called in other batch files.

for example: I have a batch file which creates packets using ncat (the new version of netcat/nc) - I use ncat to create "magic" packets to turn on a remote computer using the following command in a batch file :

ncat -u --send-only 12345 < WOL_Macs.txt

(WOL_macs.txt is a text file with the appropriate packet data for specific MACs)

However, since yesterday the command is suddenly transformed to

ncat -u --send-only 12345 0<WOL_Macs.txt

***** and the command no longer works *****

I would like to know .. Can I tell windows to process the batch file pipe in the original manner (as I have many batch files which use this method) and windows has never done this to me before.

Report •

September 29, 2012 at 17:05:44
This has been standard behavior for years now. The real question is "the command no longer works" how?

How To Ask Questions The Smart Way

Report •

Related Solutions

September 29, 2012 at 17:15:29
like i pointed out .. this "behaviour" only started yesterday

the question is: can I restore what I consider normal operation.
ie. Can i tell windows not to interfere in this manner or not ?

if so ,, how?
if not .. how do I push the data to the command in the manner I require ?

While i do appreciate your replies and you clearly understand the problem,
you have not actually offered a solution.

Perhaps you could explain how I can push the data from a file to an executing command in the manner to which (until yesterday) i was accustomed..


Report •

September 29, 2012 at 17:51:39
It's stuck in "unicode" mode? (see: cmd /?, look at options /U and /A). no, not this. see # 6.
ps: pls post the code that isn't working, and sample of the data that it is using. Then we can work from there...

Report •

September 29, 2012 at 22:52:09
follow-up: nah, it's not unicode issue, but exact as the razor says. It sucks, imho.
but mostly, it is a primative "echo" artifact which needs to be accounted for. I had never seen this before, or at least noticed it before. Unless you need the echo on, just set echo off and forget it, then you'll never see it. If you need to use the contents of the command-execute echo, then you will have to account for that F_D_ zero in the text-stream. This is all new to me.

Report •

September 30, 2012 at 10:40:09
OK - Thanks for the replies.

I will look into your suggestions and come back soon.

Report •

September 30, 2012 at 21:12:40
It's purely cosmetic. You never noticed it before because you don't normally redirect the standard streams and you don't normally run with echo on. The programs don't see it. The file isn't converted into Unicode. Consider the following:
H:\Visual Studio 2010\Projects\cn2\Release>type LNP1.3.txt a.bat ..\cn2\cn2.cpp


Lazy Newb Pack V1.3 extras installed!
Date (D/M/Y): 31/3/2011

cn2 asdf 1234 foo bar < LNP1.3.txt


#include <Windows.h>
#include <iostream>
#include <string>
int main(){
        char* cmd = ::GetCommandLine();
        std::string str;
        std::cout << "Command line: '" << cmd
                << "'\nStdIn: '";
        while (std::getline(std::cin, str))
                std::cout << str << '\n';
        std::cout << "'\n";
        return 0;

H:\Visual Studio 2010\Projects\cn2\Release>a

H:\Visual Studio 2010\Projects\cn2\Release>cn2 asdf 1234 foo bar  0<LNP1.3.txt
Command line: 'cn2  asdf 1234 foo bar '
StdIn: 'Lazy Newb Pack V1.3 extras installed!
Date (D/M/Y): 31/3/2011

H:\Visual Studio 2010\Projects\cn2\Release>

debutente: While i do appreciate your replies and you clearly understand the problem
No, no I don't. You haven't told me. It's as if your breaks were failing, and you're so focused on the squeaking noise of the pads that you refuse to acknowledge your break petal is springy and offers no resistance!

How To Ask Questions The Smart Way

Report •

September 30, 2012 at 21:50:12
@razor: I've never seen that before, with the zero and such. Like you said, though, it is only "display" and not feed, cosmetic bosh. nothing to do with unicode. If debutente is having problems, it is most likely the code, and not the cmd-echo output. If echo is "on", and you want to use the output, then you will have to anticipate the space zero:
echo ON
time <crlf > xx
type xx

c:\work\time 0<crlf :: if you needed to use this line, code for the zero.
The current time is: 0:27:43.33
Enter the new time:

the echo has no effect on the command input or output, but if you need to use the command-echo (not just output), then of course you need to code for the space and zero. otherwise, set echo off or use @ and forget it!

@op: cmd can be invoked with echo disabled, using /Q. If you want this, build it into the shortcut or the run-sequence. Then, if you need echo, use "echo on" in your batch.

Report •

October 6, 2012 at 16:41:08
I would like to say thanks to all for pointing me in the right direction and I have resolved the problem.

The reason I have never noticed it before is due to almost all of my batches starting with @echo off .. so i simply never noticed it before.

I mistook the problem for the redirected stream insertion when, in fact, my real error was due to addressing packets to an offline system which was unable to respond to ARP requests.

Although I was sending to a broadcast address the actual interface associated with the broadcast was offline at the time and so TCP/IP failed .. I now have a static ARP address for the interface and the packet is successfully sent.

I am not sure who helped me the most as you all contributed toward the fix and so you all deserve a +1.

Great work guys .. thanks for your help

My spongey brake petal is now a pedal and the brakes are working ;)

Report •

Ask Question