Hello,
If purebasic.exe is called with some options (/help, /version, /build), it does output messages to the standard output.
Problems:
- If purebasic.exe is called from a windows console window (cmd.exe), purebasic.exe opens its own console window, which is closed very quickly!
- It is not possible to redirect the output to a text file (purebasic.exe /help >help.txt). Only an empty textfile is created!
Solution: I wrote a little console application, which passes the arguments to purebasic.exe, catches the output and writes this output to the console window.
I compiled this application as PureBasic.com and copied it in to the same directory as PureBasic.exe.
This way I can use it from the windows command line and will get all outputs!
Here is the source:
Code: Select all
EnableExplicit
;{ Procedure declarations
Declare Main()
Declare PrintProgramOutput( Program, *bError.Integer = #Null )
;}
;{ Constants
#APP_TITLE = "PureBasic.com"
#APP_CONSOLE_COLOR_DEFAULT_FG = 7
#APP_CONSOLE_COLOR_DEFAULT_BG = 0
#APP_CONSOLE_COLOR_DEBUG_FG = 8
#APP_CONSOLE_COLOR_DEBUG_BG = 0
#APP_CONSOLE_COLOR_ERROR_FG = 12
#APP_CONSOLE_ERROR_DEBUG_BG = 0
#APP_EXITCODE_NOERROR = 0
#APP_EXITCODE_NOCONSOLE = 255
#APP_EXITCODE_IDE_MISSING = 254
#APP_EXITCODE_IDE_ERRORS = 253
#APP_EXITCODE_IDE_NOTSTARTED = 252
#APP_SEPARATOR = ">>>>"
;}
;{ Macros
Define DBG_ConsoleForeground, DBG_ConsoleBackground
Macro DBG( msg )
CompilerIf #PB_Compiler_Debugger
ConsoleColor( #APP_CONSOLE_COLOR_DEBUG_FG, #APP_CONSOLE_COLOR_DEBUG_BG )
PrintN( "DBG> " + msg )
ConsoleColor( #APP_CONSOLE_COLOR_DEFAULT_FG, #APP_CONSOLE_COLOR_DEFAULT_BG )
CompilerEndIf
EndMacro
Macro WAIT( msg="Press ESC to continue", key=#ESC$, exitcode=#Null )
CompilerIf #PB_Compiler_Debugger
PrintN("")
DBG( msg )
PrintN("")
While Inkey() <> key
Delay(100)
Wend
If exitcode : ProcedureReturn exitcode : EndIf
CompilerEndIf
EndMacro
Macro ErrorN( msg )
ConsoleColor( #APP_CONSOLE_COLOR_ERROR_FG, #APP_CONSOLE_ERROR_DEBUG_BG )
ConsoleError( msg )
ConsoleColor( #APP_CONSOLE_COLOR_DEFAULT_FG, #APP_CONSOLE_COLOR_DEFAULT_BG )
EndMacro
;}
End Main()
Procedure Main()
Protected PurePath.s, IDE.s
Protected Arg.s, iArg, bConsole = #False
Protected AllArgs.s
Protected prgHandle, prgID, prgError, msgError.s, prgExitCode
Protected myExitCode = #APP_EXITCODE_NOERROR
If Not OpenConsole()
MessageRequester( #APP_TITLE, "Could not open console window!", #MB_ICONERROR )
ProcedureReturn #APP_EXITCODE_NOCONSOLE
EndIf
PrintN( #APP_TITLE + " (call PureBasic.exe and prints its output to console window)" )
CompilerIf #PB_Compiler_Debugger
PurePath = #PB_Compiler_Home
CompilerElse
PurePath = GetPathPart( ProgramFilename() )
CompilerEndIf
DBG( "PurePath = " + PurePath )
IDE = PurePath + "PureBasic.exe"
DBG( "IDE Path = " + IDE )
If FileSize( IDE ) < 0
ErrorN( "PureBasic.exe does not exist in directory " + PurePath )
WAIT( "Press ESC to finish " + #APP_TITLE )
ProcedureReturn #APP_EXITCODE_IDE_MISSING
EndIf
For iArg = 0 To CountProgramParameters() - 1
Arg = ProgramParameter( iArg )
If (Left(Arg,1) = "-" Or Left(Arg,1) = "/") And Len(Arg) > 1
Arg = LCase( Right( Arg, Len(Arg)-1 ) )
Select Arg
Case "?" : bConsole = #True
Case "help" : bConsole = #True
Case "version" : bConsole = #True
Case "build" : bConsole = #True
EndSelect
EndIf
Next iArg
AllArgs = ""
For iArg = 0 To CountProgramParameters() - 1
AllArgs + ProgramParameter(iArg) + " "
Next iArg
AllArgs = Trim(AllArgs)
If Not bConsole
PrintN( "IDE PureBasic.exe is called in standard mode!" )
DBG( "Call PureBasic.exe " + AllArgs )
RunProgram( IDE, AllArgs, "" )
Else
PrintN( "PureBasic.exe is called in console mode!" )
DBG( "Call PureBasic.exe " + AllArgs )
prgHandle = RunProgram( IDE, AllArgs, "", #PB_Program_Hide | #PB_Program_Open | #PB_Program_Read | #PB_Program_Error )
If prgHandle
PrintN( #CRLF$ + #APP_SEPARATOR + " PureBasic.exe started successfully " + #APP_SEPARATOR + #CRLF$ )
While ProgramRunning(prgHandle)
If Not PrintProgramOutput(prgHandle, @prgError)
Delay(1)
EndIf
Wend
PrintProgramOutput(prgHandle, @prgError)
prgExitCode = ProgramExitCode(prgHandle)
CloseProgram( prgHandle )
PrintN( #CRLF$ + #APP_SEPARATOR + " PureBasic.exe finished execution " + #APP_SEPARATOR + #CRLF$ )
If prgExitCode
ErrorN( "PureBasic.exe finished with exit code: " + Str(prgExitCode) )
myExitCode = prgExitCode
ElseIf prgError
ErrorN( "PureBasic.exe finished with errors" )
myExitCode = #APP_EXITCODE_IDE_ERRORS
Else
PrintN( "PureBasic.exe finished without errors!" )
myExitCode = #APP_EXITCODE_NOERROR
EndIf
Else
ErrorN( "PureBasic.exe could not be started!" )
myExitCode = #APP_EXITCODE_IDE_NOTSTARTED
EndIf
EndIf
WAIT( "Press ESC to finish " + #APP_TITLE )
CloseConsole()
ProcedureReturn myExitCode
EndProcedure
Procedure PrintProgramOutput( Program, *bError.Integer = #Null )
Protected msgError.s, bPrintedOutput
While AvailableProgramOutput(Program)
PrintN( ReadProgramString(Program) )
bPrintedOutput = #True
Wend
Repeat
msgError = ReadProgramError(Program)
If msgError <> ""
ErrorN( msgError )
bPrintedOutput = #True
If *bError : *bError\i = #True : EndIf
Else
Break
EndIf
ForEver
ProcedureReturn bPrintedOutput
EndProcedure
Maybe someone can use it.
cu, guido