Page 1 of 1

View output of "print" statements when running on Windows

Posted: Wed Jan 07, 2015 10:27 pm
by Nagyhal
Does anyone know how to do this?

I've looked for solutions on sites like StackOverflow, but I don't understand any of the answers.

I have tried running T-Engine from the command line, using the ">" operator to send the standard output / error to a text file. However, it doesn't seem to do anything.

I need this because I'm working with AI.

And yes, I'm aware print is a function!

Re: View output of "print" statements when running on Window

Posted: Thu Jan 08, 2015 1:35 am
by Castler
You should have a te4_log.txt file in your T-Engine directory that contains all of the print output.

As explained in the wiki, you can add --flush-stdout to force the log file to be updated immediately. (Otherwise, it's buffered, which means that there may be a delay before print statements' output shows up.) --flush-stdout can slow the game down, and I rarely have to use it.

Re: View output of "print" statements when running on Window

Posted: Thu Jan 08, 2015 9:36 am
by Dao Zeti
Some lua files, like ai-files, disable the print function. If you find this at the start:

Code: Select all

local print = function() end
prints inside your codechanges probably won't do nothing.

If you are working with the console, the output of print (variable) / table.print (variable) is inside te4_log.txt, as Castler explained. You can flush with a keytroke (CTRL + F), if you are using Marsons wonderful Developer Tools: http://forums.te4.org/viewtopic.php?f=5 ... lit=marson

Re: View output of "print" statements when running on Window

Posted: Sat Jan 10, 2015 12:09 am
by Nagyhal
Thanks, Dao Zeti!

It's not like I hadn't discovered te4_log.txt yet! It's just that from the point of view of someone looking at the middle of the AI files, not really having paid attention to how te4_log.txt is created in the past and discovering there is no way to view the Standard Output on Windows, the conclusion of "I have problems viewing print output on Windows" is a reasonable one, especially when not willing to delegate much time to such a side issue!

Moreover people I spoke to on #ToME were similarly baffled, and I couldn't find anything after searching through every thread on here related to "print". So I figured it was high time to make a thread for people to look up and reference in future.

But really, thanks!

Re: View output of "print" statements when running on Window

Posted: Sat Jan 10, 2015 12:36 am
by Nagyhal
So for other applications, does anyone know the quickest, easiest way to view the stderr and stdout?

Re: View output of "print" statements when running on Window

Posted: Sat Jan 10, 2015 3:25 am
by Castler
Sorry; I didn't realize that some files disable print. That seems very odd, and it seems like not a great idea, since, as you saw it, can be confusing. Oh well.

stdout and stderr don't really exist for Windows apps; at least, not in a standardized setup like they do for Linux. (See here for the full details.) I don't know if there's a standard way to get at them or not. In ToME's case, it takes the (otherwise nonfunctioning, I think) stdout and redirects it to a file; see here in ToME's main.c if your curious.

Re: View output of "print" statements when running on Window

Posted: Sat Jan 10, 2015 11:33 am
by Nagyhal
Yeah, perhaps it would be better to declare a function like

Code: Select all

local debug=false
function doPrint(...)
    if debug then print(...) 
    else return nil
    end
end
Oh well, it's obvious when you know about it.

And thanks, I think I understand the general practice regarding console output a lot better now!