Output redirection?

If you are a new Irrlicht Engine user, and have a newbie-question, this is the forum for you. You may also post general programming questions here.
Post Reply
Blender3D
Posts: 7
Joined: Thu Aug 14, 2008 11:24 am

Output redirection?

Post by Blender3D »

Hello, Guys

I have a short question again: How can outputs of Irrlicht be redirected to any file (e.g. /dev/null)? I know that you cat do this when you don't call ./yourExectable but ./yourExecutable > /dev/null. But don't want to call my programm from the shell. So this dataredirection should be in the sourcecode.

Many thanks for any usefull answere!!

--Blender3D

PS: I now my english is bad :(
cat /dev/brain | sort
JP
Posts: 4526
Joined: Tue Sep 13, 2005 2:56 pm
Location: UK
Contact:

Post by JP »

Do you mean the console output?

This has been discussed before so try searching for it. I know that irrlicht's log events go through the even receiver so if there's no way of telling irrlicht where to put the events automatically you could grab them there and send them elsewhere yourself, then return true so they don't get to the console.
Image Image Image
Blender3D
Posts: 7
Joined: Thu Aug 14, 2008 11:24 am

Post by Blender3D »

Thanks for replying my post...

I will try to find something with google, the searchengine here etc. (I am so stupid that I didn't searched first)

--Blender3D
cat /dev/brain | sort
rogerborg
Admin
Posts: 3590
Joined: Mon Oct 09, 2006 9:36 am
Location: Scotland - gonnae no slag aff mah Engleesh
Contact:

Post by rogerborg »

Hmm, freopen("log.txt", "w", stdout) isn't working. I guess the modified stdout isn't usable from the DLL.

Ah well, here's the 'proper' way to do it.

Code: Select all

class LogReceiver : public IEventReceiver
{
public:
    virtual bool OnEvent(const SEvent & event)
    {
        if(event.EventType == EET_LOG_TEXT_EVENT)
        {
            log(event.LogEvent.Text);
            return true; // Stops the event getting to the Irrlicht log as well
        }
    }

    void log(const char * message)
    {
        fprintf(LogFile, "%s\n", message);
    }

    void openLogFile(const char * filename)
    {
        LogFile = fopen(filename, "w");
    }

    void closeLogFile(void)
    {
        if(LogFile)
        {
            fclose(LogFile);
            LogFile = 0;
        }
    }

    FILE * LogFile;
};

// ... then after you create your device...

    LogReceiver receiver;
    receiver.openLogFile("log.txt");
    device->setEventReceiver(&receiver);
    receiver.log("You can use the same logger for your application logging");

// ... and finally ...

    receiver.closeLogFile();
Please upload candidate patches to the tracker.
Need help now? IRC to #irrlicht on irc.freenode.net
How To Ask Questions The Smart Way
Post Reply