Hi,
I have been crawling for hours through the PB board, but I haven't found a solution yet...
Is there a way to automatically redirect the console debugger output to a file on executable startup (without having to type in the "redirect" command) ?
The reason why I'm asking is: I have to track a bug in my program at my customers shop and I can't reproduce the bug it in my office.
Thanks, javabean
Redirect console debugger output
Re: Redirect console debugger output
I found a solution. I'm using RunProgram() to redirect the output into a logfile.
Code: Select all
;Compile as "debuglogger.exe"
#LOGFILE = 0
progparamcnt.i = CountProgramParameters()
If progparamcnt = 2
progpath.s = ProgramParameter()
logpath.s = ProgramParameter()
If FileSize(progpath) > -1 And LCase(GetExtensionPart(progpath)) = "exe"
progid = RunProgram(progpath, "", "", #PB_Program_Open|#PB_Program_Read)
If progid
If OpenFile(#LOGFILE, logpath)
FileSeek(#LOGFILE, Lof(#LOGFILE))
WriteStringN(#LOGFILE, FormatDate("[%dd-%mm-%yyyy, %hh:%ii:%ss] ", Date()) + "---------- Starting debug session: " + progpath + " ----------")
While ProgramRunning(progid)
If AvailableProgramOutput(progid)
WriteStringN(#LOGFILE, ReadProgramString(progid))
EndIf
Wend
WriteStringN(#LOGFILE, FormatDate("[%dd-%mm-%yyyy, %hh:%ii:%ss] ", Date()) + "---------- Exiting debug session, " + "Exitcode: " + Str(ProgramExitCode(progid)) + " ----------")
CloseProgram(progid)
CloseFile(#LOGFILE)
Else
MessageRequester("Debuglogger", "Specified log file could not be opened!", #MB_ICONERROR)
EndIf
Else
MessageRequester("Debuglogger", "Executable could not be started!", #MB_ICONERROR)
EndIf
Else
MessageRequester("Debuglogger", "Executable not found!", #MB_ICONERROR)
EndIf
Else
MessageRequester("Debuglogger", "Usage:" +Chr(10) + "debuglogger <executable> <logfile>", #MB_ICONEXCLAMATION)
EndIf
End
Re: Redirect console debugger output
just a smal hint:
is it not necessary to jump to the end of file with FileSeek() anymore.
Greetings ... Kiffi
with the new #PB_File_Append - Flag (available since PB 5.10)javabean wrote:Code: Select all
[...] If OpenFile(#LOGFILE, logpath) FileSeek(#LOGFILE, Lof(#LOGFILE)) [...]
is it not necessary to jump to the end of file with FileSeek() anymore.
Code: Select all
[...]
If OpenFile(#LOGFILE, logpath, #PB_File_Append)
; FileSeek(#LOGFILE, Lof(#LOGFILE))
[...]
Hygge