Game Development Community

[solved] output text to the command line prompt

by Thomas Bang · in Torque Game Engine · 10/26/2009 (9:44 am) · 15 replies

How can i print some text to the command line prompt?

Con::printf only prints to the torque-console (console.log). But i need some output to the command line prompt.

#1
10/26/2009 (2:26 pm)
dPrintf
has always worked for me
#2
10/26/2009 (3:05 pm)
dPrintf is not working.

I tried also cout but when i include <iostream> i get a lot of errors.
#3
10/26/2009 (5:37 pm)
Huh. I haven't had any trouble with dPrintf. Although now that I think about it I don't remember if I ever used it in Windows.

... Try "n" at the end of each dprint statement?

edit: If that doesn't work try dFflushStdout() after dPrintf
#4
10/26/2009 (6:09 pm)
Both didnt work.
#5
10/26/2009 (6:23 pm)
Dunno. dPrintf uses vprintf, which is supposed to write to stdout, even in Windows. So it should work. I assume you're launching your Torque app from a console?
#6
10/27/2009 (3:27 am)
Yes, i start the app from the console (to be exact: from a *.bat) with some parameters attached.
#7
10/28/2009 (2:29 pm)
grr.. just realized this stupid GG post script ate the backslash in post #3. That's supposed to "[backslash]n". You probably guessed that though huh?

...edit: being Windows, perhaps it needs both the newline and carriage return characters? "[backslash]n[backslash]r" ?

Sorry, I'm just guessing. I don't have a development environment set up in Windows at the moment.
#8
10/29/2009 (3:18 am)
This is the ConsoleFunction:

ConsoleFunction(dw_writeLn,void,2,2,"")
{
	const char* text = Con::getReturnBuffer(dStrlen(argv[1])+1);
	text = argv[1];
	Con::printf("writeLn executed");
	
	dPrintf(text,"\n\r");
	dFflushStdout();
}

And the *.bat contains this line

DedServer.exe -canvas no -mode CTF -maxplayers 8

But nothing happens.
#9
10/29/2009 (12:14 pm)
OK, well the dPrintf statement isn't formatted properly. That won't append the newline that way. It should be:
dPrintf("%s\n", text);
Also, there's no need to set text = return buffer when you're just going to reset it to argv[1]. Actually, there's no need for another char* at all. Try:
dPrintf("%s\n", argv[1]);
That ought to work.

Furthermore... Is this for a dedicated server? Dedicated servers already redirect the Console input/output to the system console/command line. They certainly do in Linux at least. Do they not function similarly in Windows? I'm pretty sure they do. It's been a while but I'm sure I tested that years ago.
#10
10/30/2009 (3:46 am)
No luck. I am a little bit baffled.
#11
10/30/2009 (4:01 am)
Maybe just a @echo off line in the batch file blocking the output?
#12
10/30/2009 (4:21 am)
No, i wrote...

@echo on
#13
11/24/2009 (8:51 am)
I am so stupid. I forgot this command:

enableWinConsole(true); // or false to deactivate

Now it works.
#14
11/24/2009 (8:53 am)
Moo! :)

Glad you solved it!
#15
11/24/2009 (9:29 am)
Hint...
If you only want to output your own text and not the whole stuff from your console (console.log) you can write something like that:

function WinConOutput(%text)
{
   enableWinConsole(true); // enable the console window
   writeToConsole(%text");
   enableWinConsole(false); // disable the console window   
}

If you execute enableWinConsole(true); multiple times, the window is only started once. You will not get multiple instances of the console window. That's good.

And after enableWinConsole(false); the console window will still remain. It is not closed. That's also good.

Ups, before i forget: First insert writeToConsole as a ConsoleFunction.

ConsoleFunction(writeToConsole,void, 2,2,"")
{
   const char* text = Con::getReturnBuffer(dStrlen(argv[1])+1);
   text = argv[1];

   Con::printf("%s\n", text); // if you want a space line between to lines...
   //... otherwise write: Con::printf(text);
}