Command Prompt vs. RunProgram Output

Everything else that doesn't fall into one of the other PB categories.
Axolotl
Addict
Addict
Posts: 905
Joined: Wed Dec 31, 2008 3:36 pm

Command Prompt vs. RunProgram Output

Post by Axolotl »

EDIT: This test case example is not valid any more, because of my mistake, sorry. :oops:

I'm running into a problem. (I'm pretty sure this has already been mentioned in connection with the PB compiler calls).
What is my problem:
=> I'm missing the “error output” in RunProgram.

My Test Case (only for this message) :)
I've created a small example with copy. (The steps to reproduce are described in the output print.)
I copy files using the Copy command, then write-protect one target file and repeat the command...

Code: Select all

; Example to show my problem. 
; HINT: It is not about the Copy command itself. It is about the missing error message. 
;
Global cmd$ 

cmd$ = "copy /y/v c:\temp\*.ini r:\"  ; ret = 0 (success) or 1 (failure) 

ProcedureDLL RunCommand(Command$, WorkingDirectory$="") 
  Protected result, NProgram, t$ 

  NProgram = RunProgram("cmd.exe", "/D/C " + Command$, WorkingDirectory$, #PB_Program_Open|#PB_Program_Read|#PB_Program_Hide) 
  If NProgram 
    While ProgramRunning(NProgram)
      If AvailableProgramOutput(NProgram) 
        out$ = ReadProgramString(NProgram)    : Debug "OUT: " + out$ 
      EndIf 
      t$ = ReadProgramError(NProgram)   ; Extra double, I didn't want to miss anything.
      If t$                                   : Debug "ERR: " + t$ 
      EndIf         
    Wend                                      : Debug "" 
    t$ = ReadProgramError(NProgram)   ; Extra double, I didn't want to miss anything.
    If t$                                     : Debug "ERR: " + t$ 
    EndIf         

    result = ProgramExitCode(NProgram)        : Debug "Exitcode: " + Str(result)
    CloseProgram(NProgram) 
  EndIf
  ProcedureReturn result 
EndProcedure 

RunCommand(cmd$, "") 
Compare the outputs (this is what I got)

Code: Select all

; Command Prompt:  use this  copy /y/v c:\temp\*.ini r:\ 
; 
; First Run --> success. 
; c:\Temp>copy /y/v c:\temp\*.ini r:\
; c:\temp\aaa_test-setup.ini
; c:\temp\AH.INI
; c:\temp\AH2.INI
;         3 file(s) copied.
; 
; To prepare an Error set (one) target file to 'Read-Only' 
;
; Second Run --> success. 
; c:\Temp>copy /y/v c:\temp\*.ini r:\
; c:\temp\aaa_test-setup.ini
; c:\temp\AH.INI
; c:\temp\AH2.INI
; Access is denied.
;         2 file(s) copied.
; 
; Debug Output:  
; 
; Second Run --> Missing line in output. Everything else (the files, the exitcode) is ok. 
; OUT: c:\temp\aaa_test-setup.ini
; OUT: c:\temp\AH.INI
; OUT: c:\temp\AH2.INI
; OUT:         2 file(s) copied.
; 
; Exitcode: 1

Perhaps there is an explanation for this?
I would be grateful if someone could share this with me.
Last edited by Axolotl on Wed Dec 31, 2025 11:28 am, edited 1 time in total.
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).
infratec
Always Here
Always Here
Posts: 7766
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: Command Prompt vs. RunProgram Output

Post by infratec »

Try this:

Code: Select all

copy c:\a c:\b >stdout.txt 2>stderr.txt
And this:

Code: Select all

dir c:\a\ >stdout.txt 2>stderr.txt
You will notice that copy does not send errors to stderr.
The dir command uses stderr.

And .. .I miss #PB_Program_Error in your code

With this flag I get:
ERR: Das System kann das angegebene Laufwerk nicht finden.

Exitcode: 1
Axolotl
Addict
Addict
Posts: 905
Joined: Wed Dec 31, 2008 3:36 pm

Re: Command Prompt vs. RunProgram Output

Post by Axolotl »

Thanks infratec,
you are right. My mistake... Need to find a better/working example.
With the correct call of RunProgram() ; including the #PB_Program_Error at least this 'copy' example is not showing the issue.

Further investigation:
My current test object is the PB-Compiler.
Here, it is indeed apparent that neither stdout nor stderr are used for output during compilation.
It is also not a problem with RunProgram(), as redirection to text files in the console also produces no output (empty files).
The question remains: How can I access the output?

BTW: This output appears on the console and never in my program: (Of course, I am more interested in the error messages.)

Code: Select all

C:\Users\Axolotl>C:\APPS\PureBasic\Compilers\pbcompilerc.exe C:\SoftwareDevelopment\PureBasic\Test\MyCoolLib.pb /OPTIMIZER /PURELIBRARY /OUTPUT MyCoolLib
PureBasic 6.21 - C Backend (Windows - x64)
Compiling C:\SoftwareDevelopment\PureBasic\Test\MyCoolLib.pb
Loading external libraries...
Starting compilation...
96 lines processed.
Creating threaded version of the PureLibrary...
Starting compilation...
96 lines processed.
PureLibrary successfully created: "C:\APPS\PureBasic\purelibraries/userlibraries/MyCoolLib".

- Feel the ..PuRe.. Power -
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).
Post Reply