[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: io.popen read and write, again
- From: Petite Abeille <petite.abeille@...>
- Date: Thu, 27 Feb 2014 20:59:05 +0100
Salut Gary,
On Feb 27, 2014, at 1:09 AM, Gary V. Vaughan <gary@vaughan.pe> wrote:
>> Is using PIPESTATUS reasonable enough?
>
> That presumes /bin/sh is bash, which is not the case except on GNU/Linux -- and not all the time even there.
$ uname
Darwin
$ /bin/sh --version
GNU bash, version 3.2.51(1)-release (x86_64-apple-darwin13)
Copyright (C) 2007 Free Software Foundation, Inc.
So, looks like Mac OS X is bash friendly as well. As is, say, Cygwin.
>
>> Thoughts? Suggestions?
>>
>
> The problem with io.popen is that you cannot access both the input and output of the pipeline from Lua. But, since it uses the shell by default, you can work around this limitation with temporary files and shell redirections. For example (untested!):
Thanks for the detailed answer, appreciated.
> Caveat: obviously none of this works on Windows which is not POSIX compliant, can't fork processes, and doesn't have a shell (as such).
Right. Considering the constrained, but rather limited number of environments I have to deal with in the immediate future (linux & cygwin mostly), I don’t mind a bit of bashism to go through the day. Expediency over portability :)
FWIW, here are various POSIX ways to emulate PIPESTATUS:
http://cfajohnson.com/shell/cus-faq-2.html#Q11
https://github.com/cheusov/pipestatus
Or perhaps simply [1]:
mkfifo fifo; command2 <fifo & command1 >fifo; echo "$?”
Or something. 'set -o pipefail;’ will do for the time being though.
[1] http://mywiki.wooledge.org/Bashism