Can I catch Print before the Console?
BlitzMax Forums/BlitzMax Beginners Area/Can I catch Print before the Console?
| ||
if I run the application from CMD I see cout/print is it possible I can catch cout/print string so I can use it in my application? I want all the cout to a textarea |
| ||
For print you just need to overwrite the Print-Command for your app:SuperStrict Function print(text:string) 'add to whatever 'call original print .print(text) End Function print "hey" The other one (stderror etc): maybe connect your custom pipes to the ones used by blitzmax, so you get the stderror first. bye Ron |
| ||
Test1.debug.exe has stop working A problem caused the program to stop working correctly. Please close the program. the print come from the Lua Script I want a console output as what the MaxIDE and BLIde have |
| ||
When talking about two applications that communicate (like the MaxIDE host and your own client program), this is generally done by redirecting input and output streams for a given program (an OS feature) rather than by doing something special to the client program's implementation of Print itself. MaxIDE starts a client application with TProcess.Create and the HIDECONSOLE flag. It can then read and write to/from the program's streams using TPipeStream. Take a look at Pub.FreeProcess for the methods it uses (or, the relevant place in the MaxIDE source is Type TOutputPanel). If you aren't designing a host application to catch Print from a client application - it sounds like you just want one app that wants to redirect the output of library code designed with Print - then you can redirect Print itself by setting the value of the global StandardIOStream variable to something else, a stream that writes to wherever you need it sent (this is actually recommended in the source for Print, if you find it). You'll probably need your own TStream subclass for this. |
| ||
As yasha suggests I would suggest to replace current StandardIOStream to a file stream that outputs a log document. Print flushes the stream on any call, so it should be very reliable in case the application crashes without closing the file stream. Another option is create a lanucher for your app, and handle this from the launcher. It may sound a "too much" for a simple solution, but I've found it is a good way to provide crash reports of beta tested apps. The app lancuher could connect to an online service that sends creash reports information to you, etc... sort of what BLIde does. |
| ||
In my main loop and in MyHook I add:Lua_CMD.AddText(Print_Buff) ' Print to MyConsole Print_Buff = Null ' Clear Print_BuffBRL.StandardIO Global Print_Buff:String ' the Global Buff ... Function Print( str$="" ) ' BlitzMax Print Function Print_Buff :+ str + "~n" ' Add my Buff StandardIOStream.WriteLine str StandardIOStream.Flush End FunctionIn MyLua.bmx: Print "---------------------------------------[Run.Lua]---" Local L:Byte Ptr = luaL_newstate() luaL_openlibs(L) lua_register(L, "print", Skriv_Buff) ' When Lua print call BlitzMax: Skriv_Buff If luaL_dostring(L, _EDii.GetText()) Print "Error: " + lua_tostring(L, -1) Else Print "---------------------------------------[End.Lua]---" EndIf lua_close(L) Function Skriv_Buff:Int(_L:Byte Ptr) Print_Buff :+ luaL_checkstring(_L, 1) + "~n" Return 1 End FunctionI didn't understand Derron but think Skriv_Buff is what he meant Probably Lua have more notification I need to add this is how I understand ziggy's lanucher: MyLanucher.exe (this is the main application) Local MyApp:TProcess = TProcess.Create("MyApp", HIDECONSOLE) ' If MyApp.Status() = 1 Then Print "MyApp is running" While MyApp.Status() If MyApp.pipe.ReadAvail() Then Print_Buff = ReadLine:String(MyApp.pipe) WendI didn't test this because I can now catch the print from Lua. For me it's so cool that the console is working for both BlitzMax and Lua. This is beyond my wildest expectation what I could do in BlitzMax thank thee for the help |
| ||
With Blitzmax only the sky is the limit :-) -Henri |