zsh-users
 help / color / mirror / code / Atom feed
* Silent shell but not silent script
@ 2005-09-02 11:09 DervishD
  2005-09-02 11:30 ` Mike Hernandez
  2005-09-02 15:34 ` Bart Schaefer
  0 siblings, 2 replies; 5+ messages in thread
From: DervishD @ 2005-09-02 11:09 UTC (permalink / raw)
  To: Zsh Users

    Hi all :)

    This one is tricky ;) I have to invoke a command which writes its
diagnostic messages to stderr and its normal output to stdout. This
is important, because sometimes I will want to separate the output to
two files using redirections.

    The problem is this:

    $ ./command
    zsh: no such file or directory: ./command

    Sometimes the command I have to run won't exist, so zsh will
issue that error. How the heck can I make zsh not to spill the error
message but at the same time let the command to use stderr and
stdout? I mean, I can silent zsh doing this:

    $ ./command 2> /dev/null

    but that will silent the stderr output from the command if the
command exists.

    I cannot use MULTIOS and I cannot use any special option of zsh
because of portability, so... can this be done? Can I use any
subshell trick to do the job?

    The only solution I've found so far is to pipe stderr thru a sed
script and get rid of any shell message, but it is too much... Other
solution is doing something like this:

    $ { ./command 2>&1 } 2> /dev/null

    but then I completely loose the ability of separating the stdout
output from the stderr one :(

    Thanks a lot in advance :) and sorry for the weird question O:)

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736 | http://www.dervishd.net
http://www.pleyades.net & http://www.gotesdelluna.net
It's my PC and I'll cry if I want to...


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

* Re: Silent shell but not silent script
  2005-09-02 11:09 Silent shell but not silent script DervishD
@ 2005-09-02 11:30 ` Mike Hernandez
  2005-09-02 14:22   ` DervishD
  2005-09-02 15:34 ` Bart Schaefer
  1 sibling, 1 reply; 5+ messages in thread
From: Mike Hernandez @ 2005-09-02 11:30 UTC (permalink / raw)
  To: Zsh Users

On 9/2/05, DervishD <zsh@dervishd.net> wrote:
>     Sometimes the command I have to run won't exist, so zsh will
> issue that error. How the heck can I make zsh not to spill the error
> message but at the same time let the command to use stderr and
> stdout? I mean, I can silent zsh doing this:

Why not test to see if the command exists before doing anything with it?
Something like if [ -x $command ] ? 

Mike


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

* Re: Silent shell but not silent script
  2005-09-02 11:30 ` Mike Hernandez
@ 2005-09-02 14:22   ` DervishD
  0 siblings, 0 replies; 5+ messages in thread
From: DervishD @ 2005-09-02 14:22 UTC (permalink / raw)
  To: Mike Hernandez; +Cc: Zsh Users

    Hi Mike :)

 * Mike Hernandez <sequethin@gmail.com> dixit:
> On 9/2/05, DervishD <zsh@dervishd.net> wrote:
> >     Sometimes the command I have to run won't exist, so zsh will
> > issue that error. How the heck can I make zsh not to spill the error
> > message but at the same time let the command to use stderr and
> > stdout? I mean, I can silent zsh doing this:
> Why not test to see if the command exists before doing anything
> with it? Something like if [ -x $command ] ?

    Because that's not enough, I'm afraid. If the command is an
script with a bangpath and the interpreter doesn't exist, the
"[[ -x command ]]" test will succeed but the execution will fail. By
the way, in that case zsh will return 127 instead of the correct 126,
although if I recall correctly, that has been dealt with in latest
CVS :?

    Thanks for your suggestion :) I'm looking for something in that
line, but it's quite difficult. It has to be portable or at least
work in zsh and bash, that will cover nearly 90% of the boxes, and
that's a problem by itself.

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736 | http://www.dervishd.net
http://www.pleyades.net & http://www.gotesdelluna.net
It's my PC and I'll cry if I want to...


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

* Re: Silent shell but not silent script
  2005-09-02 11:09 Silent shell but not silent script DervishD
  2005-09-02 11:30 ` Mike Hernandez
@ 2005-09-02 15:34 ` Bart Schaefer
  2005-09-02 16:03   ` DervishD
  1 sibling, 1 reply; 5+ messages in thread
From: Bart Schaefer @ 2005-09-02 15:34 UTC (permalink / raw)
  To: Zsh Users

On Sep 2,  1:09pm, DervishD wrote:
}
}     Sometimes the command I have to run won't exist, so zsh will
} issue that error. How the heck can I make zsh not to spill the error
} message but at the same time let the command to use stderr and
} stdout?

As far as I can tell, it's impossible.

Redirections are done *before* the command execution is attempted,
which is why this ...

}     $ ./command 2> /dev/null

... succeeds in suppressing the error message.  But that also means
that this ...

}     $ { ./command 2>&1 } 2> /dev/null

... does *not* succeed in suppressing the error, it only succeeds in
sending the error to stdout.

}     The only solution I've found so far is to pipe stderr thru a sed
} script and get rid of any shell message

I'd have suggested 'grep -v "^zsh:"', or egrep with a more specific
set of messages to suppress.


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

* Re: Silent shell but not silent script
  2005-09-02 15:34 ` Bart Schaefer
@ 2005-09-02 16:03   ` DervishD
  0 siblings, 0 replies; 5+ messages in thread
From: DervishD @ 2005-09-02 16:03 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: Zsh Users

    Hi Bart :)

 * Bart Schaefer <schaefer@brasslantern.com> dixit:
> On Sep 2,  1:09pm, DervishD wrote:
> }     Sometimes the command I have to run won't exist, so zsh will
> } issue that error. How the heck can I make zsh not to spill the error
> } message but at the same time let the command to use stderr and
> } stdout?
> As far as I can tell, it's impossible.

    That's what I suppose :(
 
> Redirections are done *before* the command execution is attempted,
> which is why this ...

    Yes, I've noticed from the shell error message suppression.
 
> }     The only solution I've found so far is to pipe stderr thru a sed
> } script and get rid of any shell message
> I'd have suggested 'grep -v "^zsh:"', or egrep with a more specific
> set of messages to suppress.

    Is it faster than sed? Anyway, I don't know under which kind of
shell my script will run (that's the main problem, because I'm sure
there is a way of 'shutting up' zsh), so it's almost impossible to
distinguish between valid lines from the command and the shell error
message, I can only do assumptions and that's not a good idea... That
said, there is no point in using neither grep nor sed :(

    The whole point of all this mess is my 'mobs' project, a building
system. The main program is a (portable) script, but I allow a 'hook'
to be run in order to extend the main script capabilities (for
example to do autoconf-like checks, etc.). Currently I force the
'hook' to be a shell script and it is run like this:

    [ -f "0.hook" ] && {
        # Things
        sh -c ". ./0.hook" || exit $?
        # More things
    }

    I want to allow the hook to be any kind of binary, no matter if a
script-with-a-bangpath or a real binary, but then the problem is the
one I explained in my first message: it's impossible to know if the
command execution failed or if the command returned with an error
(the worst case is when the command returns with 126 or 127, of
course). I'm afraid I'm not going to be able to remove the current
limitation :((( Any idea is welcome, of course ;)

    Thanks for your explanation.

    Raúl Núñez de Arenas Coronado

-- 
Linux Registered User 88736 | http://www.dervishd.net
http://www.pleyades.net & http://www.gotesdelluna.net
It's my PC and I'll cry if I want to...


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

end of thread, other threads:[~2005-09-02 16:00 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-09-02 11:09 Silent shell but not silent script DervishD
2005-09-02 11:30 ` Mike Hernandez
2005-09-02 14:22   ` DervishD
2005-09-02 15:34 ` Bart Schaefer
2005-09-02 16:03   ` DervishD

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).