Hi,

I have made a small service program in C++. I use printf to print debug/log
messages.

When I redirect output to a log file "myprogram > log.txt" the file log.txt
stays empty.

My program can be recompiled for Linux, and here the same thing happens.

I have done a minimal C++ program, here redirection works fine.

What can cause command line redirection not to work as expected?

Thanx in adv
Tage

Re: command line redirection doesn't work with console c++ program by Doug

Doug
Thu Apr 13 11:34:34 CDT 2006

On Thu, 13 Apr 2006 18:19:27 +0200, Tage Korsdal Nielsen <tkn@korsdal.dk>
wrote:

>Hi,
>
>I have made a small service program in C++. I use printf to print debug/log
>messages.
>
>When I redirect output to a log file "myprogram > log.txt" the file log.txt
>stays empty.
>
>My program can be recompiled for Linux, and here the same thing happens.
>
>I have done a minimal C++ program, here redirection works fine.
>
>What can cause command line redirection not to work as expected?

How are you running the program? It is the command shell that performs the
redirection, so you must run it through the shell.

--
Doug Harrison
Visual C++ MVP

Re: command line redirection doesn't work with console c++ program by Chen

Chen
Thu Apr 13 11:35:50 CDT 2006

Tage Korsdal Nielsen wrote:
> Hi,
>
> I have made a small service program in C++. I use printf to print
> debug/log messages.
>
> When I redirect output to a log file "myprogram > log.txt" the file
> log.txt stays empty.
>
> My program can be recompiled for Linux, and here the same thing happens.
>
> I have done a minimal C++ program, here redirection works fine.
>
> What can cause command line redirection not to work as expected?
>
> Thanx in adv
> Tage

Are you writing to stdout or stderr?

Try with "myprogram %> log.txt" (redirect all output channels to file)...

Not sure about the syntax on linux. It might be "&>" instead of "%>"...

// Chen