Watcom printf to stdout, I don't get it :-(

B

bine

Sorry, I found a lot of old stuff, even kind of flamewars about
good+bad style whatsoever..

I simply want any hint that works!

I try to migrate older stuff from NT and newer stuff from Linux/AIX to
run on Windows2003 as well. I use the
Open Watcom C32 Optimizing Compiler Version 1.3
Portions Copyright (c) 1984-2002 Sybase, Inc. All Rights Reserved.

I simply want some lines to be printed to stdout directly, like a
simple hello.c consisting of basically
printf("my text\n");

This is only printed when I call the programm with a redirection
("hello | tee x" or "hello > x"). The problem is mentioned a lot here
in older comp.* messages. But all the "soultions" I found+tried didn't
work as well.

I tried alternatively:

fflush(stdout);
getch();
getchar();
AFTER the printf, and

setvbuf(stdout,NULL,_IONBF,0);
BEFORE that line

and even
fprintf(stderr,"my text\n");
because I read somewhere stderr would never be buffered...?

So if there is someone with the patience to explain what to do I could
stick to watcom. Otherwise I'd have to throw it away and look for
something else...

Thanks a lot,
bine
 
A

Alan Balmer

Sorry, I found a lot of old stuff, even kind of flamewars about
good+bad style whatsoever..

I simply want any hint that works!

I try to migrate older stuff from NT and newer stuff from Linux/AIX to
run on Windows2003 as well. I use the
Open Watcom C32 Optimizing Compiler Version 1.3
Portions Copyright (c) 1984-2002 Sybase, Inc. All Rights Reserved.
Questions about specific compilers and implementations are off-topic
here. The Watcom compiler defaults to fully buffered output, but I
think that fact is misleading you in this case.
I simply want some lines to be printed to stdout directly, like a
simple hello.c consisting of basically
printf("my text\n");

This is only printed when I call the programm with a redirection
("hello | tee x" or "hello > x"). The problem is mentioned a lot here
in older comp.* messages. But all the "soultions" I found+tried didn't
work as well.

I tried alternatively:

fflush(stdout); This should work.
getch();
getchar();
These have no applicability here.
AFTER the printf, and

setvbuf(stdout,NULL,_IONBF,0);
This should work if used *before* the first I/O to stdout.
BEFORE that line

and even
fprintf(stderr,"my text\n");
because I read somewhere stderr would never be buffered...? This should work.

So if there is someone with the patience to explain what to do I could
stick to watcom. Otherwise I'd have to throw it away and look for
something else...
My suspicion is that you have something wrong in your program, or you
are seeing a phenomenon due to your OS, since the suggested solutions
should have eliminated the Watcom buffering peculiarity. Did you check
the return value of the functions (fflush, setvbuf, printf) that you
used? Post the smallest compilable example which demonstrates the
problem, and we'll take a look at it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top