You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Redirect stderr from inner functions using command substitutions ("subshells") #1035
It does not seem to be possible to redirect stderror from inner functions using "subshells".
functionexample_errorif not contains '-a' b c
echo'Not contains'elseecho'Contains'
end
end
functionexample_runnerset -l result (example_error)
echo$result
end
example_runner ^/dev/null
This will give:
contains: Unknown option “b”
/home/terje/test.fish (line 2): if not contains '-a' b c
^
in function “example_error”,
called on line 10 of file “/home/terje/test.fish”,
in command substitution
called on line 10 of file “/home/terje/test.fish”,
in function “example_runner”,
called on line 14 of file “/home/terje/test.fish”,
Not contains
There are two different ways to solve this:
Either do the redirection within the subshell (example_error ^/dev/null) or wrap everything inside a fish call fish -c 'example_runner' ^/dev/null. Neither solution is very good.
Reacted by Colin de Roos, Yngvar Kristiansen, Amanda Vaz and Aksel Rasmussen
While working on the fix for issue #4211 I noticed that the exec_subshell() function only collects the stdout of the sub shell. This means that any output written to stderr by fish script run via that function is written to file descriptor 2 and cannot be redirected (e.g., to /dev/null) or otherwise processed by the code that calls exec_subshell(). This is broken. It's also an example of how the current fish design for managing file descriptors and stdin/stdout/stderr is problematic.I'm going to work around this by documenting that argparse validation code write error messages to stdout rather than the more natural stderr. But having to do so is quite annoying.
changed the title [-]Redirect stderr from inner functions using "subshells"[/-][+]Redirect stderr from inner functions using command substitutions ("subshells")[/+]on Aug 11, 2017
I'm not sure if this is the same bug or a different one,
But I wanted to do something like this
echo foo >/nonexistent/path 2>/dev/null
Where any write error for the redirect get's silenced.
Obviously that doesn't work as the error isn't produced by echo but fish itself.
However, I thought these would work:
Which they didn't, and using subshells or functions like the start of this issue suggested doesn't work either. Using eval also doesn't work.
The only solution I could get working is to use fish -c but I'd rather nat (as I have to then ensure everything I pass to it is properly escaped, and will likely be way slower).
Activity
faho commentedon Jul 5, 2017
I copied @ridiculousfish's assignment from #2927. Hope that's okay!
krader1961 commentedon Jul 18, 2017
From my opening problem description in #4224:
While working on the fix for issue #4211 I noticed that the exec_subshell() function only collects the stdout of the sub shell. This means that any output written to stderr by fish script run via that function is written to file descriptor 2 and cannot be redirected (e.g., to /dev/null) or otherwise processed by the code that calls exec_subshell(). This is broken. It's also an example of how the current fish design for managing file descriptors and stdin/stdout/stderr is problematic.I'm going to work around this by documenting that argparse validation code write error messages to stdout rather than the more natural stderr. But having to do so is quite annoying.
[-]Redirect stderr from inner functions using "subshells"[/-][+]Redirect stderr from inner functions using command substitutions ("subshells")[/+]IsaacOscar commentedon Oct 26, 2023
I'm not sure if this is the same bug or a different one,
But I wanted to do something like this
Where any write error for the redirect get's silenced.
Obviously that doesn't work as the error isn't produced by
echobut fish itself.However, I thought these would work:
Which they didn't, and using subshells or functions like the start of this issue suggested doesn't work either. Using
evalalso doesn't work.The only solution I could get working is to use
fish -cbut I'd rather nat (as I have to then ensure everything I pass to it is properly escaped, and will likely be way slower).