zsh-users
 help / Atom feed
* getting the status of the left-hand side of a pipe in the right-hand side
@ 2019-08-01 15:43 Vincent Lefevre
  2019-08-01 16:49 ` Bart Schaefer
  0 siblings, 1 reply; 3+ messages in thread
From: Vincent Lefevre @ 2019-08-01 15:43 UTC (permalink / raw)
  To: zsh-users

I would like to get the status of the left-hand side of a pipe
in the right-hand size. Knowing whether it has terminated or not
should be sufficient.

Information is probably known from the job table:

zira% sleep 2 | { sleep 1; jobs }
[1]    running    sleep 2
zira% sleep 2 | { sleep 3; jobs }
[1]    done       sleep 2

but there may be other jobs in the session, so that I need to get
the right one.

The goal is that in the following

  ( trap '' INT; "$@" | { (less); kill -PIPE 0 } )

I want to avoid the "kill -PIPE 0" if the command "$@" has terminated,
in order to get its exit status.

-- 
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: getting the status of the left-hand side of a pipe in the right-hand side
  2019-08-01 15:43 getting the status of the left-hand side of a pipe in the right-hand side Vincent Lefevre
@ 2019-08-01 16:49 ` Bart Schaefer
  2019-08-01 22:44   ` Vincent Lefevre
  0 siblings, 1 reply; 3+ messages in thread
From: Bart Schaefer @ 2019-08-01 16:49 UTC (permalink / raw)
  To: Zsh Users

[-- Attachment #1: Type: text/plain, Size: 731 bytes --]

On Thu, Aug 1, 2019, 8:44 AM Vincent Lefevre <vincent@vinc17.net> wrote:

> I would like to get the status of the left-hand side of a pipe
> in the right-hand size. Knowing whether it has terminated or not
> should be sufficient.
>
> Information is probably known from the job table
>

This is not the case in general.  The job status is only communicated by
the OS to the direct parent of the job, and the job table typically becomes
static in any subshell (it used to be completely erased in subshells but
people wanted to examine output of "jobs" for prompts etc.).

So you might be able to find the job from the job table but the best you
can reliably do for its status is to send it a "kill -0" and see if that
returns error.

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: getting the status of the left-hand side of a pipe in the right-hand side
  2019-08-01 16:49 ` Bart Schaefer
@ 2019-08-01 22:44   ` Vincent Lefevre
  0 siblings, 0 replies; 3+ messages in thread
From: Vincent Lefevre @ 2019-08-01 22:44 UTC (permalink / raw)
  To: zsh-users

On 2019-08-01 09:49:03 -0700, Bart Schaefer wrote:
> So you might be able to find the job from the job table but the best you
> can reliably do for its status is to send it a "kill -0" and see if that
> returns error.

Can I assume that the left-hand side is the last job in the table
(this seems to be the case in all the tests I've done)?

That would be nice as a precise status is provided: either "running"
or the exit status. And this would be very useful as it appears that
$pipestatus no longer contains the expected value if the jobs builtin
is used:

zira% false | { sleep 1; jobs } ; echo $pipestatus
[1]    exit 1     false
0

i.e. "0" instead of "1 0". Is this a bug? At least, this is not
documented.

-- 
Vincent Lefèvre <vincent@vinc17.net> - Web: <https://www.vinc17.net/>
100% accessible validated (X)HTML - Blog: <https://www.vinc17.net/blog/>
Work: CR INRIA - computer arithmetic / AriC project (LIP, ENS-Lyon)

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, back to index

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-01 15:43 getting the status of the left-hand side of a pipe in the right-hand side Vincent Lefevre
2019-08-01 16:49 ` Bart Schaefer
2019-08-01 22:44   ` Vincent Lefevre

zsh-users

Archives are clonable: git clone --mirror http://inbox.vuxu.org/zsh-users

Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.zsh.users


AGPL code for this site: git clone https://public-inbox.org/ public-inbox