![]() |
![]() |
#1 |
Returning fan!
Join Date: Jan 2011
Location: Montréal, QC, Canada
Posts: 1,456
|
ARexx RC is 0 Even When Command Fails
Hi there!
I'm developing some ARexx scripts to test systematically players but I run into a problem with the following code: Code:
IF ~SHOW('P', 'AMIGAAMP') THEN DO ADDRESS Command 'Run AmigaAMP' SAY 'Result1: ' || RC SAY 'Result2: ' || Result ... Code:
AmigaAMP: Unknown command AmigaAMP failed returncode 10 ![]() (I tried redirecting the output of Run to a file using Run >T:Output but it contains only the CLI name, not the two error lines, which are still printed out in the Shell...) What am I missing? Tygre |
![]() |
![]() |
#2 |
Registered User
Join Date: Jan 2019
Location: Germany
Posts: 3,497
|
The problem is most likely the shell and not Arexx. What the "Run" command does is that it takes the rest of the command line without even looking, then spawns a new shell, and leave it to the new shell to work on this command line. Since "Run" is asynchronous, there is no way by the spawned shell to communicate any results back to the shell that launched it. The RC=0 result in this case only tells you "Yup, I could create a new shell for you succesfully".
You find more information on this in the autodocs of the System() call - this is how Run works (or at least, as of 3.2 it does.) |
![]() |
![]() |
#3 |
Registered User
Join Date: Oct 2009
Location: Germany
Posts: 3,326
|
Check out the example WaitForPort (a command usually placed in Rexxc) in ARexxGuide: http://aminet.net/search?query=arexxguide2
Further I would first check the path of your command AmigaAMP with "IF EXISTS(<filespec>)" where <filespec> is the full path to AmigaAMP and if not exist exit the script with error message. More or less on top of your script. Code:
/**/ /* @{" SHOW() " link ARx_Func2.ag/SHOW()} can be used to check for the existence of a port */ if ~show('P', 'VLT') then do address command /* both RUN and WAITFORPORT are DOS commands.*/ 'run >nil: vlt:VLT' /* The loop below assures that the program will wait at least 50 seconds for the port to open, but will exit as soon as the port is available. */ do 5 while ~show('P', 'VLT') 'waitforport VLT' end address /* @{" toggle " link ARx_Instr.ag/ADDRESS 23} back to previous address */ /* The return code RC is set to 5 when WaitForPort times out ** ** before the port is available. */ if rc = 5 then do say 'Unable to load VLT' exit end end |
![]() |
![]() |
#4 |
Returning fan!
Join Date: Jan 2011
Location: Montréal, QC, Canada
Posts: 1,456
|
Hi Thomas and Daxb!
Thanks for your answers! ![]() Yes, you're right of course, Thomas, it's the Run command creating a new shell... I wonder if there is a way to redirect the output of this new shell somewhere where I could look at it? I tried with >T:Output after Run and after AmigaAMP but still its output (like AmigaAMP: Unknown command) appears in the current Shell window. I don't mind using a special command: I'm using Run only because AmigaAMP doesn't detach itself from the current Shell. That's a good idea, Daxb, the do 5 while ~show('P', 'VLT') but actually I'd like to avoid that if possible. Actually, currently, I'm using WaitForPort, which times out after 10 seconds or so if the port doesn't appear ![]() Cheers! |
![]() |
![]() |
#5 |
Registered User
Join Date: Jan 2019
Location: Germany
Posts: 3,497
|
Unfortunately, if ARexx does not provide this functionality, there is no possibility on the shell level. The "command not found" is printed by the shell, through its standard output, and not by the command, through the current output. The ">" only redirects the output of commands. You could try to redirect the error output via "*>" which works from shell V45 upwards, but I doubt that this is making any difference here as redirection kicks in too late (i.e. when the command is started, not when the shell is interpreting commands).
The System() function call provides this functionality, but I afraid ARexx interface to the shell is too "simple minded" to give you this possibility. |
![]() |
![]() |
#6 | |
Registered User
Join Date: Oct 2009
Location: Germany
Posts: 3,326
|
Quote:
![]() |
|
![]() |
![]() |
#7 |
Returning fan!
Join Date: Jan 2011
Location: Montréal, QC, Canada
Posts: 1,456
|
Hi Thomas and Daxb!
Thanks a lot for your replies, I'll check if ARexx could "redirect" the output of Run, else I'll use Daxb's method ![]() Cheers! |
![]() |
![]() |
#8 |
Returning fan!
Join Date: Jan 2011
Location: Montréal, QC, Canada
Posts: 1,456
|
PS. At the end, I used WaitForPort because it straightforward and it either returns 0 immediately (if the port is available) or timeouts after 10 sec. and returns 5 (if the port is unavailable).
Code:
IF ~SHOW('P', programPort) THEN DO ADDRESS Command 'Run >' || tempFile || ' ' || programName ADDRESS Command 'WaitForPort ' || programPort IF RC ~= 0 THEN DO SAY 'Could not start ' || programName || ', is it in the path?' EXIT END SAY programName || ' has started.' END ELSE DO SAY programName || ' was already started.' END |
![]() |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
[opus5][arexx] "Lister Empty..." command - problem | peceha | Coders. Scripting | 16 | 20 March 2018 09:42 |
AREXX Help | Zetr0 | support.Other | 2 | 26 January 2011 23:09 |
arexx help | jimbobrocks92 | Coders. General | 4 | 19 January 2011 12:50 |
Arexx | redblade | request.Apps | 2 | 30 August 2006 11:51 |
Arexx | Seti | Coders. General | 2 | 05 August 2003 18:59 |
|
|