* Capturing "jobs" output.
@ 1997-01-08 21:32 Xris Laas
1997-01-09 2:19 ` Zoltan Hidvegi
0 siblings, 1 reply; 2+ messages in thread
From: Xris Laas @ 1997-01-08 21:32 UTC (permalink / raw)
To: zsh-users
I have noticed some unexpected behavior in the "jobs" builtin. It is
possible to redirect its output to a file, but any piping of any sort
fails miserably. Note these examples:
---------------------------------
% jobs
[1] + suspended (tty input) cat
[2] running sig-updater
% jobs > foo.tmp
% cat foo.tmp
[1] + suspended (tty input) cat
[2] running sig-updater
% jobs | cat
% echo $(jobs)
% cat <(jobs)
% cat =(jobs)
---------------------------------
I found the "cat =(jobs)" lack of output especially surprising, since I
would expect it to be equivalent to "jobs > /tmp/xxx ; cat /tmp/xxx".
Clearly, at some point, the output is not being redirected, or maybe is
not being printed at all. I looked through the source of builtins.c
and jobs.c, but the "fout" variable seems to check out OK. I'm not
familiar with Zsh internals, but I'd guess that one of those nested
if's in printjob() (jobs.c) is filtering out the redirections before
anything is printed. I can work around it for now by just using a temp
file, but could someone look into this?
Thanks,
--Xris
--
... that whenever any form of government becomes destructive of these
ends, it is the right of the people to alter or to abolish it, and to
institute new government, laying its foundation on such principles,
and organizing its powers in such form, as to them shall seem most
likely to effect their safety and happiness.
-- Thomas Jefferson, Prologue, "Declaration of Independence"
{ Chris "Xris" Laas }----{ chrisl@cybercom.net }----{ xris@qfl.com }
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: Capturing "jobs" output.
1997-01-08 21:32 Capturing "jobs" output Xris Laas
@ 1997-01-09 2:19 ` Zoltan Hidvegi
0 siblings, 0 replies; 2+ messages in thread
From: Zoltan Hidvegi @ 1997-01-09 2:19 UTC (permalink / raw)
To: chrisl; +Cc: zsh-users
> I have noticed some unexpected behavior in the "jobs" builtin. It is
> possible to redirect its output to a file, but any piping of any sort
> fails miserably. Note these examples:
>
> ---------------------------------
> % jobs
> [1] + suspended (tty input) cat
> [2] running sig-updater
> % jobs > foo.tmp
> % cat foo.tmp
> [1] + suspended (tty input) cat
> [2] running sig-updater
> % jobs | cat
> % echo $(jobs)
> % cat <(jobs)
> % cat =(jobs)
> ---------------------------------
Note that in all cases when jobs seemingly failed it was in a subshell. A
subshell is created by fork() and it does not inherit child processes from its
parent so its job table is empty. The only way to pass jobs output to a
process is using the
jobs > >(...)
syntax. Unfortunately zsh does not wait for the >(...) process to terminate
which is probably a bug which will hopefully be fixed (together with some
other serious signal related bugs).
A simple pipe does not work since the left-hand side of a pipe is always
executed in a subshell in zsh. In bash it is the right-hand side which is
executed in a subshell so jobs | cat works in bash but echo foo | read bar
does not set bar. In ksh both jobs|cat and echo foo|read bar works. I guess
that it first checks wether one of the pipe commands is not an external
command and it tries to execute the non-external side in the current shell.
That hack can be implemented in zsh (I think it would be very simple to add
this feature) but you can never rely on such thing in a portable script.
POSIX explicitely defines the behaviour unspecified here.
Zoltan
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1997-01-09 2:46 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1997-01-08 21:32 Capturing "jobs" output Xris Laas
1997-01-09 2:19 ` Zoltan Hidvegi
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).