PBCompiler in Console vs. RunProgram

Just starting out? Need help? Post your questions and find answers here.
Axolotl
Addict
Addict
Posts: 885
Joined: Wed Dec 31, 2008 3:36 pm

PBCompiler in Console vs. RunProgram

Post 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." 
Just because it worked doesn't mean it works.
PureBasic 6.04 (x86) and <latest stable version and current alpha/beta> (x64) on Windows 11 Home. Now started with Linux (VM: Ubuntu 22.04).