-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RFC: process redirections #1271
RFC: process redirections #1271
Conversation
Looks really cool! @StefanKarpinski will have to review. |
Superficial review: looks great. I will take a deeper look at the code a bit later. I especially enjoy that relatively few and simple changes were made to allow this (which I guess says that the original design was not terrible). Beautiful work,@carlobaldassi . @JeffBezanson, is there anything we can do about operator precedence to remove the need for parens here without messing up normal comparisons? |
Not really. One could try to exploit the call to |
Thanks. The original design is indeed very nice and easy to extend (once you get it...). `cmd` >& {1=>"out.txt", stderr_stream=>"err.txt"} # two redirs at a time
`cmd` >& {2=>1} | `cmd2` # pipe everything to cmd2
`cmd` >& {3=>1,1=>2,2=>3} # flip out and err ...uhm, time for me to go to sleep I guess. |
Reminds me of the plan9 shell syntax: http://plan9.bell-labs.com/sys/doc/rc.html |
That seems like a pretty reasonable idea although I'm not certain how to make it work. I guess that `cmd` >& {1=>2,2=>1} We can figure out that a temporary is needed to implement that. It's a little harder to program, but much easier to use. |
wow, it really does. I had no idea about that. BTW while reading I recalled that I had a question: is there a way to specify Anyway, the Dict idea has at least one drawback: as proposed, one can't specify modes (e.g. if one wants to append to stdout). First solution: have different operators Second solution: optional annotations, e.g. something like I don't have a preference.
The problem here is that both BTW another slightly annoying precedence issue is that I guess that there are just a few ways to deal with all this: 1) give up and keep the brackets 2) change notation and abandon comparison operators (e.g. use |
(3) isn't so bad if it's part of the backtick parser. |
Sorry, I just realized that the way I had implemented here-strings had a buffering problem, and besides it was just silly. I fixed it, and it's also much cleaner now. |
I've actually considered this because it would be nice to be able to write |
Disclaimer: I've only been working on the internals, I've never even read the backticks parser's code. That said, I think building a whole Julia shell within backticks will lose a lot in term of programming capabilities. Maybe if it's just redirections (possibly including pipes, which however would need to also keep their current syntax) it could make sense, as long as it doesn't bring in the need for the escaping-rules hell which shells (the ones I know of at least) are notorious for; I'm not sure that's possible, but I think I could try to prototype something in a few days if I find the time and if it's ok with you. |
Let's try to come up with something that's not at the backticks syntax level. I'm ok with having |
This could be represented with redirection to |
For Windows you want |
Fine by me!
In the DOS prompt it used to be |
|
Shall we merge this then? It looks good to me. A lot of stuff will have to be rewritten when we merge the Windows port, but that's ok. |
I'm going to merge. We can always revert if anyone starts yelling about it ;-) |
enhanced process redirections
This addresses #307 (and does a little more). There are 2 commits:
Notice that I had to use
.>
for stderr, since2>
is obviously unavailable. I also had to add.>>
to the parser. This is as close I could get to the familiar shell syntax without introducing too many new operators, but if anyone comes up with a nicer alternative it would be great.All forms have a mirror counterpart, e.g.
and can be used together, since the result of
(>)(::Cmd,::String)
is a Cmd, although they require brackets:which of course is a side-effect of using comparison operators and inheriting their precedence rules (one more reason to think of some alternative notation, if possible).
Everything works the same when using IOStreams instead of Strings:
but of course in that case there are no append operators, since the mode is inherited from the stream.
Apart from notation issues, I think the internals are sound, as I basically extended what's already done for pipes.
There are also the mirror versions
<<<
,&<
and&<<
So, even more extra operators...