Redirect console debugger output

Just starting out? Need help? Post your questions and find answers here.
javabean
User
User
Posts: 60
Joined: Sat Nov 08, 2003 10:29 am
Location: Austria

Redirect console debugger output

Post by javabean »

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
javabean
User
User
Posts: 60
Joined: Sat Nov 08, 2003 10:29 am
Location: Austria

Re: Redirect console debugger output

Post by javabean »

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
User avatar
Kiffi
Addict
Addict
Posts: 1485
Joined: Tue Mar 02, 2004 1:20 pm
Location: Amphibios 9

Re: Redirect console debugger output

Post by Kiffi »

just a smal hint:
javabean wrote:

Code: Select all

[...]
  If OpenFile(#LOGFILE, logpath)
    FileSeek(#LOGFILE, Lof(#LOGFILE))
[...]
with the new #PB_File_Append - Flag (available since PB 5.10)
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))
[...]
Greetings ... Kiffi
Hygge
Post Reply