Here is what I tried
ls | to json | save fileList.json
open fileList.json | from json | save error.log
open fileList.json | from json | save --stderr error.log
It didn't save anything to file error.log
FYI, added the (useless)second part | from json to create error message to save it.
Tried below example from help save but didn't work:
> do i {} | save foo.txt --stderr foo.txt
Error: nu::shell::cant_convert
× Can't convert to Closure.
╭─[entry #62:1:1]
1 │ do i {} | save foo.txt --stderr foo.txt
· ┬
· ╰── can't convert string to Closure
╰────
You are using
savecorrectly, but you are missing that nu's internal commands do not "print to stderr".If you want to catch an internal command (e.g.
ls) that might fail, usetryandcatch:If you want to capture the output that an external command (e.g. cat) has sent to STDOUT or STDERR in a
doblock, you can usesavejust like you have tried:But with external commands you can more directly also use
out>,err>, andout+err>to channel their raw streams:Finally, you might also be interested in using
completewhich provides you withstdout,stderr, andexit_codeas keys in a record (which you can then further process like withto text | save …orto json | save …orget stderr | save …etc.):