Page 1 of 2

Execute with CaptureOutput set to true doesn't returns rc

Posted: Tue Sep 08, 2026 3:18 pm
by bitRocky
Execute() should return the rc of the program which gets executed if CaptureOutput is set to true, but it doesn't work here on MorphOS.
It always returns 0.

Did I something wrong?

Here is an example with tries to execute an unknown command "Echo2".

Code: Select all

@VERSION 11,0

rc, out = Execute("Echo2", "Hallo", {CaptureOutput=True})
DebugPrint("rc = "..rc)
DebugPrint("out = "..out)
If rc = 0
	DebugPrint("Successful")
Else
	DebugPrint("Failed!")
Endif

Re: Execute with CaptureOutput set to true doesn't returns rc

Posted: Tue Sep 08, 2026 3:34 pm
by plouf
Do you have latest hollywood11?
Some fixes have been made for this

Relative discusion -> https://forums.hollywood-mal.com/viewtopic.php?t=4225

Re: Execute with CaptureOutput set to true doesn't returns rc

Posted: Tue Sep 08, 2026 4:30 pm
by bitRocky
Yes v11 here on MorphOS

Re: Execute with CaptureOutput set to true doesn't returns rc

Posted: Tue Sep 08, 2026 9:40 pm
by plouf
try the following example i test it in mos now works
comment/uncomment the two Run()

Code: Select all

Function p_HandlerFunc(msg)
	Switch(msg.action)
	Case "RunFinished":
		NPrint("Return code "..StrStr(msg.returncode))
		NPrint("Press Return to continue.")
		WaitLeftMouse()
	EndSwitch
EndFunction

InstallEventHandler({RunFinished = p_HandlerFunc})

;Run("ed","",{Returncode=True})     ; returncode 0
Run("sss","",{Returncode=True})   ; dont exist not return code in win / returncode 10 in amigaos

Repeat
	WaitEvent
Forever

Re: Execute with CaptureOutput set to true doesn't returns rc

Posted: Tue Sep 08, 2026 9:50 pm
by bitRocky
I wanted to use Execute (), because it didn't have to run asynchronously.
And it should work according to the docs.

Re: Execute with CaptureOutput set to true doesn't returns rc

Posted: Sun Sep 13, 2026 4:11 pm
by airsoftsoftwair
Your code is correct. But I'm not sure if it's a bug or a feature. I mean you're trying to execute a non-existing program here and technically non-existing programs can't return a return code so one could also say that it's correct for Execute() to behave that way. I need to check how this behaves on other platforms and then decide about some sensible behaviour here...

Re: Execute with CaptureOutput set to true doesn't returns rc

Posted: Sun Sep 13, 2026 6:39 pm
by plouf
based on discusion we had in https://forums.hollywood-mal.com/viewtopic.php?t=4225 returncode must be what OS does

the following example works
in amigaos3.x by returning code 10 (As the OS does),
works in windows by returning 127 (as the OS does)

but not in Morphos/AmigaOS4
In morphos i see thext "failed code 10" in output text (as the OS does print in shell by executing a command)..bug or "feature"?
in AmigaOS4, works with 68kbinary, with ppc binary i see "return code 10" , if ed started without argument (missing) and "return code 0" if fail

Code: Select all

rc, output =Execute("ed","d",{CaptureOutput=True,Consolemode=True})   ; dont exist not return code in win / returncode 10 in amigaos
;rc, output =Execute("not_ed","",{CaptureOutput=True})   ; dont exist not return code in win / returncode 10 in amigaos

NPrint("Return code "..StrStr(rc))
NPrint("output "..output)
Repeat
	WaitEvent
Forever

Re: Execute with CaptureOutput set to true doesn't returns rc

Posted: Mon Sep 14, 2026 7:45 pm
by bitRocky
airsoftsoftwair wrote: ↑Sun Sep 13, 2026 4:11 pm Your code is correct. But I'm not sure if it's a bug or a feature. I mean you're trying to execute a non-existing program here and technically non-existing programs can't return a return code so one could also say that it's correct for Execute() to behave that way. I need to check how this behaves on other platforms and then decide about some sensible behaviour here...
It also doesn't returns a returncode if the program exists.

Code: Select all

@VERSION 11,0

rc, out = Execute("c:RequesteChoice", "Hallo", {CaptureOutput=True})
DebugPrint("rc = "..rc)
DebugPrint("out = "..out)
If rc = 0
	DebugPrint("Successful")
Else
	DebugPrint("Failed!")
Endif

Re: Execute with CaptureOutput set to true doesn't returns rc

Posted: Sun Sep 20, 2026 4:37 pm
by airsoftsoftwair
bitRocky wrote: ↑Mon Sep 14, 2026 7:45 pm It also doesn't returns a returncode if the program exists.
Huh? C:RequesteChoice doesn't exist or is that a typo?

Re: Execute with CaptureOutput set to true doesn't returns rc

Posted: Sun Sep 20, 2026 4:52 pm
by bitRocky
It exists, but I only use one argument and miss the second necessary argument, to get sure that it returns a returncode (20).

Because you said that Execute() only doesn't return a returncode, if the command doesn't exists.