A simple one...(I hope)

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
Bob Finnie
Posts: 49
Joined: Tue Jan 23, 2007 12:36 pm
Location: Bedford, UK

A simple one...(I hope)

Post by Bob Finnie »

Hi Folks,
Currently I use the following code to suppress the console output window:

Code: Select all

#pragma comment(linker, "/SUBSYSTEM:windows /ENTRY:mainCRTStartup")
Is there a way to remove the window as above but pipe the output that would normally go there into a file? A kind of running log file.

Any help would be much appreciated

Regards,
Bob
wITTus
Posts: 167
Joined: Tue Jun 24, 2008 7:41 pm
Location: Germany

Post by wITTus »

Yes you can tie cout etc. to an ofstream IIRC. See the c++ stdlib documentation. If you use only the Irrlicht Logger, it's even easier:

- Write a class which inherits from IEventReceiver
- Then in OnEvent(const SEvent& Event), you need to test for Event.EventType == EET_LOG_TEXT_EVENT
- If your test is true, you'll find the string in Event.LogEvent.Text
Generated Documentation for BlindSide's irrNetLite.
"When I heard birds chirping, I knew I didn't have much time left before my mind would go." - clinko
FuzzYspo0N
Posts: 914
Joined: Fri Aug 03, 2007 12:43 pm
Location: South Africa
Contact:

Post by FuzzYspo0N »

Code: Select all

void logToFile(const c8* str)
{
			if(GNULLDevice)
			{
				io::IWriteFile* wFile = GNULLDevice->getFileSystem()->createAndWriteFile(mFilename.c_str(), true);
				io::IXMLWriter* xmllol = GNULLDevice->getFileSystem()->createXMLWriter(wFile);
				core::stringw* p = new core::stringw(L"");
				p->append(str);
				xmllol->writeText(p->c_str());
				xmllol->writeLineBreak();
				delete p;
				p = NULL;
			}
}
heres something that might help. I use xml writer cos its easier.

Edit : GNULLDevice is a IrrlichtDevice created with a EDT_NULL_DRIVER
Bob Finnie
Posts: 49
Joined: Tue Jan 23, 2007 12:36 pm
Location: Bedford, UK

Post by Bob Finnie »

Thanks both of you for that.
Solved!
cobra
Posts: 371
Joined: Fri Jan 23, 2009 2:56 am
Location: United States
Contact:

Post by cobra »

It's even simpler than that. Somewhere at the beginning of your code, put this:

Code: Select all

std::freopen("test.txt", stdout);
std::freopen("test2.txt, stderr);
Anything you use to normally print to a console window using printf or cout will now be put into this file. :)
Josiah Hartzell
Image
vitek
Bug Slayer
Posts: 3919
Joined: Mon Jan 16, 2006 10:52 am
Location: Corvallis, OR

Post by vitek »

There are some caveats to that trick though. I know it won't work if the Irrlicht library and the user code link a different version of the C library (i.e., Irrlicht compiles with /MD and user code compiles with /MT or vice-versa). I think you might also run into troubles if running code that is a pure windows app, but I'm not certain about that.

Travis
Post Reply