Page 1 of 1

PBCompiler in Console vs. RunProgram

Posted: Fri Nov 07, 2025 1:19 pm
by Axolotl
It seems to me that the compiler is being called with different options.
The example calls the compiler in three different ways.
Simply compare the output ...... first and second in the console, third in debug window.

BTW: In this example it doesn't matter, that (under windows) you don't have the permission to write the library.
This is only about the issue that (in my opinion) the output is different/maybe incorrect?

Windows Only?

Code: Select all

EnableExplicit 

Global PBCompiler$, Params$, Flag$, SourceFile$, Compiler, StdOut$, StdErr$ 

;/--- Change the following variables to your system --- 

PBCompiler$ = "C:\Program Files\PureBasicBETA\compilers\pbcompilerc" 
SourceFile$ = "C:\SoftwareDevelopment\PureBasic\UserLibraryCodes\UserLib_MessageBoxEx.pb" 

;/--- Compile with and without this parameter (by commenting) 
Flag$ = "--quiet " 


; Build/Create the necessary strings .....
If FindString(PBCompiler$, " ") 
  PBCompiler$ = #DQUOTE$ + PBCompiler$  + #DQUOTE$ 
EndIf 

Params$ = SourceFile$ + " --optimizer " + "--purelibrary --output " + GetFilePart(SourceFile$, #PB_FileSystem_NoExtension) 
  
; Run the Compiler 
Debug "Start Compiler. Close console to continue" 

Compiler = RunProgram("cmd", "/D/C color 2 & " + PBCompiler$ + " " + Params$ + " & echo. & pause", "", #PB_Program_Wait) 
If Not Compiler 
  Debug "Error: Compiler not found: " + PBCompiler$  
EndIf 
Debug "Done." 

Debug "" 
Debug "Alternative 2 " 

Params$ = SourceFile$ + " --optimizer " + Flag$ + "--purelibrary --output " + GetFilePart(SourceFile$, #PB_FileSystem_NoExtension) 
  
; Run the Compiler 
Debug "Start Compiler. Close console to continue" 

Compiler = RunProgram("cmd", "/D/C color 2 & " + PBCompiler$ + " " + Params$ + " & echo. & pause", "", #PB_Program_Wait) 
If Not Compiler 
  Debug "Error: Compiler not found: " + PBCompiler$  
EndIf 
Debug "Done." 


Debug "" 
Debug "Alternative 3" 

Compiler = RunProgram(PBCompiler$, Params$, "",  #PB_Program_Open|#PB_Program_Read|#PB_Program_Error|#PB_Program_Hide) 
If Not Compiler 
  Debug "Error: Compiler not found: " + PBCompiler$  
Else 
  While ProgramRunning(Compiler)
    If AvailableProgramOutput(Compiler)
      StdOut$ = ReadProgramString(Compiler) ; blocking function 
      Debug "Out: " + StdOut$ 
    EndIf 
    StdErr$ = ReadProgramError(Compiler)  ; none blocking function 
    If Asc(StdErr$) 
      Debug "Err: " + StdErr$ 
    EndIf
  Wend
  CloseProgram(Compiler)
EndIf 

Debug "Done."