That sound right to me. The exit status of the program is set some time after it exits (by means of a unix signal triggering a Smalltalk semaphore which wakes up a process that updates the status in the ExternalUnixOSProcess).
For a simple command line program like this, just waiting a couple hundred milliseconds after you evaluate the command will allow time for the program to run and for Squeak to be informed of the outcome. So a retry loop with 200ms delay is probably fine in this case. Come to think of it, there's an OSProcess class>>waitForCommand: that will probably do exactly what you want in this case.
Dave
On Fri, Feb 08, 2013 at 10:17:29AM -0500, Louis LaBrunda wrote:
Hey Dave,
Thanks for the info. Looking at the code, I see that ExternalUnixOSProcess is returned from "OSProcess command:...". It has some nice methods for checking if the command finished ok.
I added some code to the method that calls irsend to check if the command is finished and if it was successful, looping on a small delay. If after awhile it has not finished successfully I try again for a few times and then give up. Since I'm sure the irsend command is fine, the errors should just be transient of the odd timing nature and retrying should work.
Lou
There are a couple of ways that a unix program can provide error output. The exit status is a simple way to communicate either success, or one of possibly several not so successful outcomes. This is useful for programs that are used in shell scripts for example. The other way is for the program to write error messages to its stderr output stream. This is common for programs for which which a user is expected to read the error messages.
I don't see anything in the man page for irsend that explains the exit status values, so it's a good bet that 0 means goodness and anything else means not so good. That might not be enough information to change the channel on your TV, but as you say I'd go ahead and try that first and see if it is good enough.
If you need to read the error output from the stdout stream (i.e. the error messages that would normally go to the console when you run the irsend program), you can do this by loading the CommandShell package from SqueakMap, then do something like this:
irsend := ProxyPipeline command: 'irsend foo bar baz'.
irsend last processProxy ==> an ExternalUnixOSProcess with pid 4157 on /usr/bin/irsend (complete, normal termination with status 1)
irsend errorUpToEnd ==> 'irsend: could not connect to socket irsend: No such file or directory '
But I think this is more complexity than you really need for this, so definitely you should first try just checking for exit status 0 and see if that does what you need.
Dave
On Thu, Feb 07, 2013 at 11:37:17AM -0500, Louis LaBrunda wrote:
Hi Dave,
Last night I left the RasPi running my Squeak code to change the channels. Most worked just fine. One of the calls to "OSProcess command:..." says it had a "... normal termination with status 1". It didn't change the channel. I will look through the code for what this and other status codes mean but can you tell me or point me to some docs.
I would like to test for errors and retry. For now I think I will just test for non zero.
Lou
On Tue, 5 Feb 2013 17:22:50 -0500, "David T. Lewis" lewis@mail.msen.com wrote:
On Tue, Feb 05, 2013 at 03:55:14PM -0500, Louis LaBrunda wrote:
On Mon, Feb 04, 2013 at 02:07:12PM -0500, Louis LaBrunda wrote: > Hi Guys, > > I would like to call irsend (a program that is part of lirc package) from > Squeak on the Raspberry Pi. Can anyone please post some sample code. >
I'm not familiar with it myself, but if irsend is just a simple command line program then I should think that you could call it easily using OSProcess.
Thanks for the reply. OSProcess sounds like it is what I need but I can't find any install instructions, probably because I don't know much about Squeak and Linux and I'm not sure where to look.
Open a SqueakMap Package Loader:
world -> open... -> SqueakMap Catalog
In the SqueakMap Package Loader, select package OSProcess. Expand that category and you will find entries for version 4.4.11 and for "head". Either one is fine, but I usually recommend just using the latest version, so select "head" and install it.
Assuming that you want to run irsend with some command line parameters, try inspecting the following expression (but use some command parameters that actually do something):
OSProcess command: 'irsend foo bar baz'
The result will be an instance of ExternalUnixOSProcess that is a proxy for the actual irsend program that you just executed. You can send it #succeeded to see if the command was evaluated without error.
I think this is sufficient for what you are trying to do, but you can also do fancier things with external programs if you load CommandShell (also on SqueakMap).
For additional background see http://wiki.squeak.org/squeak/708 and http://wiki.squeak.org/squeak/1914.
Follow up questions welcome :)
Dave
Louis LaBrunda Keystone Software Corp. SkypeMe callto://PhotonDemon mailto:Lou@Keystone-Software.com http://www.Keystone-Software.com
Louis LaBrunda Keystone Software Corp. SkypeMe callto://PhotonDemon mailto:Lou@Keystone-Software.com http://www.Keystone-Software.com