View output of "print" statements when running on Windows

All development conversation and discussion takes place here

Moderator: Moderator

Post Reply
Message
Author
Nagyhal
Wyrmic
Posts: 282
Joined: Tue Feb 15, 2011 12:01 am

View output of "print" statements when running on Windows

#1 Post 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!

Castler
Thalore
Posts: 153
Joined: Mon Mar 25, 2013 10:09 pm

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

#2 Post 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.
Qi Daozei (QDZ) - an Oriental-themed fantasy game for T-Engine. ToME Tips - auto-generated spoilers for ToME.

Dao Zeti
Higher
Posts: 79
Joined: Sun Oct 19, 2014 2:02 pm

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

#3 Post 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

Nagyhal
Wyrmic
Posts: 282
Joined: Tue Feb 15, 2011 12:01 am

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

#4 Post 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!
Last edited by Nagyhal on Sat Jan 10, 2015 1:39 am, edited 3 times in total.

Nagyhal
Wyrmic
Posts: 282
Joined: Tue Feb 15, 2011 12:01 am

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

#5 Post by Nagyhal »

So for other applications, does anyone know the quickest, easiest way to view the stderr and stdout?

Castler
Thalore
Posts: 153
Joined: Mon Mar 25, 2013 10:09 pm

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

#6 Post 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.
Last edited by Castler on Sat Jan 10, 2015 2:41 pm, edited 1 time in total.
Qi Daozei (QDZ) - an Oriental-themed fantasy game for T-Engine. ToME Tips - auto-generated spoilers for ToME.

Nagyhal
Wyrmic
Posts: 282
Joined: Tue Feb 15, 2011 12:01 am

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

#7 Post 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!

Post Reply