Repository navigation
Description
Question
I'm having trouble invoking an external command and redirecting stderr (to /dev/null) while piping stdout to the next step.
Maybe there's some other kind of redirection I should be using? Maybe it's a bug?
Sample:
> sudo apt update | filter {|line| $line | str contains --ignore-case "can be upgraded" }
WARNING: apt does not have a stable CLI interface. Use with caution in scripts.
╭───┬──────────────────────────────────────────────────────────────────────╮
│ 0 │ 6 packages can be upgraded. Run 'apt list --upgradable' to see them. │
│ │ │
╰───┴──────────────────────────────────────────────────────────────────────╯
Almost what I want, except for the ugly WARNING that didn't flow into the pipe.
(try to) Fix it by redirecting stderr:
> sudo apt update err> /dev/null | filter {|line| $line | str contains --ignore-case "can be upgraded" }
Hit:1 http://us.archive.ubuntu.com/ubuntu lunar InRelease
Hit:2 http://us.archive.ubuntu.com/ubuntu lunar-updates InRelease
Hit:3 http://packages.microsoft.com/repos/code stable InRelease
Hit:4 http://us.archive.ubuntu.com/ubuntu lunar-backports InRelease
Hit:5 https://packages.microsoft.com/repos/edge stable InRelease
Hit:6 http://security.ubuntu.com/ubuntu lunar-security InRelease
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
6 packages can be upgraded. Run 'apt list --upgradable' to see them.
Does suppress the WARNING, but now filter isn't getting any input...
At first I though this had something to do with sudo, but you can repro with nonprivileged external dir command
> dir -l . argle | filter {|x| $x | str contains Music}
dir: cannot access 'argle': No such file or directory
╭───┬────────────────────────────────────────────────────────╮
│ 0 │ .: │
│ │ total 89 │
│ │ drwxr-xr-x 2 bobhy bobhy 2 Aug 18 21:12 Desktop │
│ │ drwxr-xr-x 2 bobhy bobhy 3 Sep 6 14:20 Documents │
│ │ drwxr-xr-x 2 bobhy bobhy 25 Sep 6 23:47 Downloads │
│ │ drwxr-xr-x 2 bobhy bobhy 2 Aug 18 21:12 Music │
│ │ drwxr-xr-x 3 bobhy bobhy 3 Aug 25 13:18 Pictures │
│ │ drwxr-xr-x 2 bobhy bobhy 2 Aug 18 21:12 Public │
│ │ │
╰───┴────────────────────────────────────────────────────────╯
The missing directory error is reported to stderr as in the previous case.
I don't quite get why each newline-delimited line of output wasn't broken into a separate line item, like it seems to have done with sudo apt, but never mind: the key thing is filter returned a list with one element, as desired.
> dir -l . argle err> /dev/null | filter {|x| $x | str contains Music}
.:
total 89
drwxr-xr-x 2 bobhy bobhy 2 Aug 18 21:12 Desktop
drwxr-xr-x 2 bobhy bobhy 3 Sep 6 14:20 Documents
drwxr-xr-x 2 bobhy bobhy 25 Sep 6 23:47 Downloads
drwxr-xr-x 2 bobhy bobhy 2 Aug 18 21:12 Music
drwxr-xr-x 3 bobhy bobhy 3 Aug 25 13:18 Pictures
drwxr-xr-x 2 bobhy bobhy 2 Aug 18 21:12 Public
Note that the dir output isn't being piped into filter,at all, apparently.
Additional context and details
No response
Activity
fdncred commentedon Sep 8, 2023
I can only think of 3 things that I'd try.
sudo apt update | filter {|line| $line | str contains --ignore-case "can be upgraded" } err> /dev/null. Seems illogical, but I'm curious.do -i {sudo apt update | filter ...} | complete | get stdout, which isn't the same but may work.atuinrun-external --redirect-stderr atuin search "--interactive" | complete | $in.stderrI agree with you that
sudo apt update err> /dev/null | filter {|line| $line | str contains --ignore-case "can be upgraded" }seems like it should work. I'm not sure what's going on.@WindSoilder, any ideas about this?
horasal commentedon Sep 8, 2023
I'm not sure but a quick look through
eval.rs, it may be:aptis tiggered throughrun-externalbut it does not always cache stdout to pipelineworkround can be use
run-externalwith--redirect-stderrand--redirect-stdout:the following quick patch makes
err>pipestdout(but it breaksout>:(WindSoilder commentedon Sep 12, 2023
Sorry, I don't have much idea, I can try to look into this when I get time
Redirect: support redirect stderr with piping stdout to next commands. (
Redirect: support redirect stderr with piping stdout to next commands. (
Redirect: support redirect stderr with piping stdout to next commands. (