liljencrantz / crush

Crush is a command line shell that is also a powerful modern programming language.
MIT License
1.84k stars 35 forks source link

redirect stdout, stderr to whatever #2

Closed omac777 closed 4 years ago

omac777 commented 4 years ago

I noticed your use of the '|' to enclose hold the usual move incoming command line arguments into owned memory variables.

I also distinguished your use of the same '|' to redirect the standard output to the following tool. Your work is innovative because you're taking some of the rust syntax and putting into something that looks like bash.

Where I perceive limitations are the redirecting of stdout(standard output) and stderr(standard error) both of them to different things. I think it is doable. Will you break the existing convention when you integrate this capability in your tool?

Example to redirect stdout/stderr two different files:

foo > stdout.txt 2> stderr.txt

Example to redirect stdout/stderr into same file:

foo > allout.txt 2>&1

A proposal of acceptable crush syntax:

find example_data/tree 2>stderrFromFind.txt | select "file" 2>stderrFromSelect.txt | sort %file 2>stderrFromSort.txt
liljencrantz commented 4 years ago

The | pipelines in Crush do not generally transfer binary data, they transfer structured data. To redirect it to/from a file, it would need to be serialized/deserialized, so standard IO redirection like in bash becomes pointless. Currently, the syntax for doing so is the to and from methods of the file type, as such:

./file_list:to (ls)
./file_list:from
user         size  modified                  type      file
liljencrantz  1386 2020-04-02 23:41:10 +0200 file      ideas
liljencrantz  4096 2019-11-22 21:56:30 +0100 directory target
...