Author Topic: Command line redirect (win32)  (Read 19994 times)

mene mene tekel

  • Guest
Command line redirect (win32)
« on: March 05, 2007, 07:40:41 PM »
Hi,

I compiled a win32 console progamme and link it using

alink -oPE -subsys con ... -o example.exe

Running the program prints to the console (using printf from crtdll.dll), but trying an output redirection to a file like

example.exe 1>OutputFile.txt

the console outputs are gone, a file named OutputFile.txt is created, BUT nothing is written in!

Anybody an idea where the problem is?

Thanks!

PS: working in Microsoft Windows XP [Version 5.1.2600]

nobody

  • Guest
Re: Command line redirect (win32)
« Reply #1 on: March 05, 2007, 10:38:14 PM »
I'm only certified for beginner questions, but I'll take a flying wild-asmed guess...

There's an issue about "flushing the buffer" - "printf" doesn't really output anything until you "flush the buffer". Normally, this would happen with a newline sequence, or when your program exits. You can also "fflush(stdout)". If your string doesn't end with "13, 10, 0", this might cause different behavior depending on whether it's redirected or not.

Just a guess - it could also be a "Microsoft problem".

Best,
Frank

mene mene tekel

  • Guest
Re: Command line redirect (win32)
« Reply #2 on: March 06, 2007, 05:44:49 PM »
Hi Frank,

You are right! I implemented an additinal _fflushall() and it works!
Amazing is, that I knew about this issue but because my string ends with 13,10,0 I decided flushing cannot be the reason - and again, I learned something new ;-)

Thanks,
Martin

Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: Command line redirect (win32)
« Reply #3 on: March 07, 2007, 05:01:37 AM »
Me too! (sometimes you need it even *with* a newline!) Thanks for the confirmation, Martin!

Best,
Frank