Command Line - Programmer

This is a discussion on Command Line - Programmer ; I wounder if anyone here can either direct me to the correct group to answer this question or maybe explain to me how the cmd console processes attributes. My problem is: I have a GUI application that can detect if ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: Command Line

  1. Command Line

    I wounder if anyone here can either direct me to the correct group to
    answer this question or maybe explain to me how the cmd console
    processes attributes. My problem is:

    I have a GUI application that can detect if it's executed from a
    command line. If it has all messageboxes are outputted as text to the
    console. But when I try to redirect to a logfile like this
    "c:\myapp_dir>myapp /? > logfile.log" it stops outputing to screen and
    I get a ERROR_INVALID_HANDLE when calling WriteConsole() method. Also
    "logfile.log" is empty.

    Anybody know why? Or know where to look for possible answer?

    Regards,
    Carl.


  2. Re: Command Line

    nwsgrp1@googlemail.com wrote:
    > I wounder if anyone here can either direct me to the correct group to
    > answer this question or maybe explain to me how the cmd console
    > processes attributes. My problem is:
    >
    > I have a GUI application that can detect if it's executed from a
    > command line. If it has all messageboxes are outputted as text to the
    > console. But when I try to redirect to a logfile like this
    > "c:\myapp_dir>myapp /? > logfile.log" it stops outputing to screen and
    > I get a ERROR_INVALID_HANDLE when calling WriteConsole() method. Also
    > "logfile.log" is empty.
    >
    > Anybody know why? Or know where to look for possible answer?
    >
    > Regards,
    > Carl.
    >

    WriteConsole() simply cannot write to the handle that you get when
    output has been redirected to either a file or a pipe.

    If WriteConsole() fails with ERROR_INVALID_HANDLE, retry the operation
    with WriteFile().

    I usually wrap WriteConsole() in a function that look something like this:

    static BOOL bWriteConsoleFailed = FALSE;
    void MyWriteConsole(...)
    { switch (bWriteConsoleFailed) {
    case FALSE:
    if (WriteConsole(...)) break;
    if (GetLastError()==ERROR_INVALID_HANDLE)
    bWriteConsoleFailed = TRUE;
    else
    ; // something really bad
    case TRUE:
    if (WriteFile(...)) break;
    // something really bad
    }
    // any necessary cleanup
    }

    Norm

    --
    --
    To reply, change domain to an adult feline.


+ Reply to Thread