When launching a PB/CC program with redirection of STDERR, STDERR output goes nowhere, the documentation stating "unless it has been redirected" nothwithstanding.
I was recently informed by PB Support that the error is in fact in the documentation, as the compiler was not designed to support redirection of the STDERR function (or perhaps not designed to support redirection of STDERR to somewhere other than where STDOUT is redirected?).
PB has added a New Feature Suggestion to support independent redirection of the STDERR function.
Until such time as that feature might be implemented, here is a program demonstrating both the problem and the solution
Instructions: Compile the program; then execute from the command line or command-file using
DEMO PROGRAM SOURCE CODE
MCM
I was recently informed by PB Support that the error is in fact in the documentation, as the compiler was not designed to support redirection of the STDERR function (or perhaps not designed to support redirection of STDERR to somewhere other than where STDOUT is redirected?).
PB has added a New Feature Suggestion to support independent redirection of the STDERR function.
Until such time as that feature might be implemented, here is a program demonstrating both the problem and the solution
Instructions: Compile the program; then execute from the command line or command-file using
Code:
CMD /C stderr1.exe 1>my_stdout.txt 2>my_stderr.txt
Code:
' STDERR1.BAS ' 11.09.08 ' Demonstration of how to redirect 'stderr' output to a file; ' PB/CC STDERR function does not support this (help files 4x, 5.0 notwithstanding) ' Author: MIchael Mattias Racine WI ' Date: Nov 9 2008 ' To run demo: ' Compile program, ' Run from command line or command file using: ' CMD /C stderr1.exe 1>my_stdout.txt 2>my_stderr.txt #COMPILE EXE #COMPILER PBCC #DIM ALL #INCLUDE "WIN32API.INC" FUNCTION STDERR2 (s AS STRING) AS LONG LOCAL hStdErr AS LONG, hFile AS LONG hStdErr = GetStdHandle (%STD_ERROR_HANDLE) hFile = FREEFILE ' NOTE: can open for OUTPUT if desired; however, this results in only the ' LAST "STDERR2" command being stored in the file. ' i.e., when using OPEN FOR APPEND you must remember to delete the output file ' before writing to STDERR file or you will get outputs from prior runs. OPEN HANDLE hStdErr FOR APPEND AS hFile PRINT #hFile, S CLOSE hFile END FUNCTION FUNCTION PBMAIN () AS LONG LOCAL Z AS LONG FOR Z = 1 TO 10 STDOUT USING$ ("STDOUT line #", Z) NEXT FOR Z = 1 TO 10 STDERR USING$ ("STDERR line #", Z) NEXT ' COMMENT NEXT THREE LINES OUT TO PROVE TO YOURSELF STDERR function ' produces no output when redirected to file. FOR Z = 1 TO 10 STDERR2 USING$ ("STDERR2 line #", Z) NEXT MessageBeep %MB_OK PRINT "End of job" ' ' **************************************** ' NEW BUG I FOUND CREATING THIS DEMO ' DOC for PRINT SAYS... ' " Output of the PRINT statement cannot be redirected to a file or device, ' it always goes to the current active console screen." ' Demo shows PRINT output goes nowhere, either. ' Compiler is not creating a console when STDOUT is redirected, ' even when needed to support PRINT verb? ' Will be reported. ' ******************************************** WAITKEY$ END FUNCTION
Comment