Page 1 of 1

Checking ARexx port availability

Posted: Sat Apr 02, 2016 12:13 pm
by jPV
I'm planning to make Hollywood programs which would interact with many other programs via their ARexx ports, but I haven't found any functions to check if a port is available yet. It would be needed to check if a program is running, before trying to send ARexx commands randomly to it. Hollywood programs seem to exit with an error message when you send an Arexx command to a non existing port.

With actual ARexx scripts I do that with SHOW('P', 'PORTNAME') and with the Lua implementation in MorphOS with ipc.checkport('portname'), but what could I use with Hollywood?

One workaround could be using the ARexx for that with something like this RunRexxScript("RETURN SHOW('P','JUKEBOX')", True), but it has disadvantages like not working out of the box on MorphOS, because user would need to install 3rd party rexxsyslib.library first, so I'd really prefer a native builtin solution in Hollywood. Is there some obvious function or would this post be better in feature requests? :)

Edit: actually SendRexxCommand() function seems to require the working ARexx implementation (rexxsyslib.library) too, so it won't work directly under plain MorphOS either. I first thought these would work like the Lua implementation or RXCmd in MorphOS which bypasses the ARexx itself when just sending commands to ARexx ports (when not running any scripts, just send the command and receive the result). Well, this functionality definitely would be a feature request next ;)


Maybe some kind of WaitForPort function could be handy too if you need to wait for a launched program to appear? Like ipc.waitforport(name[, interval]) in MorphOS's Lua implementation.

Re: Checking ARexx port availability

Posted: Sun Apr 03, 2016 9:19 pm
by airsoftsoftwair
jPV wrote:I'm planning to make Hollywood programs which would interact with many other programs via their ARexx ports, but I haven't found any functions to check if a port is available yet. It would be needed to check if a program is running, before trying to send ARexx commands randomly to it. Hollywood programs seem to exit with an error message when you send an Arexx command to a non existing port.

With actual ARexx scripts I do that with SHOW('P', 'PORTNAME') and with the Lua implementation in MorphOS with ipc.checkport('portname'), but what could I use with Hollywood?
Just disable automatic error handling using ExitOnError() for the time being and then use GetLastError() to check if an error occurred.
One workaround could be using the ARexx for that with something like this RunRexxScript("RETURN SHOW('P','JUKEBOX')", True), but it has disadvantages like not working out of the box on MorphOS, because user would need to install 3rd party rexxsyslib.library first, so I'd really prefer a native builtin solution in Hollywood. Is there some obvious function or would this post be better in feature requests? :)

Edit: actually SendRexxCommand() function seems to require the working ARexx implementation (rexxsyslib.library) too, so it won't work directly under plain MorphOS either. I first thought these would work like the Lua implementation or RXCmd in MorphOS which bypasses the ARexx itself when just sending commands to ARexx ports (when not running any scripts, just send the command and receive the result). Well, this functionality definitely would be a feature request next ;)


Maybe some kind of WaitForPort function could be handy too if you need to wait for a launched program to appear? Like ipc.waitforport(name[, interval]) in MorphOS's Lua implementation.
Actually, I don't really know much about Rexx and I haven't touched Hollywood's ARexx code for 10 years or so, hence I think it would be better if the MorphOS guys came up with a native rexxsyslib implementation or just drop in the OS3 library. Any serious stuff with Rexx will require the lib anyway...

Re: Checking ARexx port availability

Posted: Tue Apr 05, 2016 6:13 pm
by jPV
airsoftsoftwair wrote:
jPV wrote:I'm planning to make Hollywood programs which would interact with many other programs via their ARexx ports, but I haven't found any functions to check if a port is available yet. It would be needed to check if a program is running, before trying to send ARexx commands randomly to it. Hollywood programs seem to exit with an error message when you send an Arexx command to a non existing port.

With actual ARexx scripts I do that with SHOW('P', 'PORTNAME') and with the Lua implementation in MorphOS with ipc.checkport('portname'), but what could I use with Hollywood?
Just disable automatic error handling using ExitOnError() for the time being and then use GetLastError() to check if an error occurred.
In any case it would be better if there would be a dedicated function to check the ports. It would be a clean solution to check which other programs are available if you have several options to interact with, and it's a good practise to check availability before sending lots of ARexx commands somewhere and then wonder the results. But I guess I can live with that RunRexxScript workaround...
Any serious stuff with Rexx will require the lib anyway...
No, I planned to do the serious stuff with Hollywood and just utilize the ports/commands on other programs :) Just like I do with Lua... I like to keep with one language at time and there's no need to mess more with the actual ARexx language if you just want to utilize what some programs offer through the port.


Another issue which came up with ARexx now is the SendRexxCommand() funtcion. The documentation tells like this:
res$ = SendRexxCommand(port$, cmd$)

This function sends the command specified in cmd$ to the Rexx port specified in port$. The function will then return the result from the command. The return value will always be a string - even if it contains just a number.
But I can't get the result like that no matter which programs I try it with and it looks that it never return the results of the sent commands.

I found a workaround to that by injecting couple of other ARexx commands with the actual command, but it kind of kills the elegancy of the SendRexxCommand...

Here's an example of both cases:

Code: Select all

DebugPrint("Test1: "..SendRexxCommand("AMIRC.1", "GETMYNICK"))
DebugPrint("Test2: "..SendRexxCommand("OWB.1", "GETURL"))
DebugPrint("Test3: "..SendRexxCommand("AMIRC.1", "OPTIONS RESULTS;GETMYNICK;RETURN RESULT"))
DebugPrint("Test4: "..SendRexxCommand("OWB.1", "OPTIONS RESULTS;GETURL;RETURN RESULT"))
End 
Output looks like this:
Test1:
Test2:
Test3: jPV
Test4: http://www.hollywood-mal.com/help.html

So, it doesn't work like written in the manual...

Re: Checking ARexx port availability

Posted: Wed Apr 06, 2016 10:24 pm
by airsoftsoftwair
jPV wrote: In any case it would be better if there would be a dedicated function to check the ports. It would be a clean solution to check which other programs are available if you have several options to interact with, and it's a good practise to check availability before sending lots of ARexx commands somewhere and then wonder the results. But I guess I can live with that RunRexxScript workaround...
The problem is that you are in a multitasking environment so even if there was a function like PortExists() it would still be unreliable because the port can go away at any time. So PortExists() could return TRUE and SendRexxCommand() could still fail because the program has been closed in the meantime. Well, I'll think about it ... maybe I'll add such a function for a future version. Wouldn't be much of a problem but it will always be unreliable because of the multitasking environment.
No, I planned to do the serious stuff with Hollywood and just utilize the ports/commands on other programs :) Just like I do with Lua... I like to keep with one language at time and there's no need to mess more with the actual ARexx language if you just want to utilize what some programs offer through the port.
But 99% of the people have rexxsyslib.library anyway on MorphOS :)
But I can't get the result like that no matter which programs I try it with and it looks that it never return the results of the sent commands.

I found a workaround to that by injecting couple of other ARexx commands with the actual command, but it kind of kills the elegancy of the SendRexxCommand...

So, it doesn't work like written in the manual...
Right, I can confirm this behaviour. But I'm not sure whether this is a bug or a feature because all my knowledge of ARexx has pretty much vanished. I never was an ARexx guy. I just read up on it when I wrote the Hollywood ARexx library which must have been in 2006 or so. But since then I've almost forgotten everything about Rexx :( The only thing I remember was that the implementation had to be done quite carefully and that the whole thing was quite fragile and not everything was documented so I'm very reluctant to touch anything here unless it's proven to be a bug...

Looking at your code I could of course extend SendRexxCommand() to always extend the command in the way you did. So if your script does

Code: Select all

SendRexxCommand("XXX", "CMD")
then SendRexxCommand() could be modified to do this instead:

Code: Select all

SendRexxCommand("XXX", "OPTIONS RESULTS;CMD;RETURN RESULT")
But I'm not sure if there are any implications, e.g. for commands which don't return anything. Additionally, it would also break compatibility with older scripts which might expect the old behaviour which is of course a no go since keeping compatibility always is of a very high priority. But the main problem is really my vanished knowledge of ARexx. That's why I'm pretty much unable to judge what would be the best way to do it. But I must have had some reason why I implemented it the way I did it... but I don't remember them :/