Skip to content
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

Oil syntax for exec {fd}<file.txt #673

Open
andychu opened this issue Mar 21, 2020 · 4 comments
Open

Oil syntax for exec {fd}<file.txt #673

andychu opened this issue Mar 21, 2020 · 4 comments

Comments

@andychu
Copy link
Contributor

andychu commented Mar 21, 2020

In other words, expose something like fd_state.Open(). You can't use plain open() because of the colliding file descriptor problem, discussed on PR #672 .

It should be scoped like shell's redirect and Python's with. So that means it involves Oil Blocks #631 .


I tried to use this syntax here:

https://github.com/oilshell/oil/blob/master/test/spec-runner.sh#L93

@andychu
Copy link
Contributor Author

andychu commented Oct 3, 2020

Maybe do something like perl:

https://perldoc.perl.org/functions/open

open '>' file.txt :out {  
  echo foo >& $out
}

@andychu
Copy link
Contributor Author

andychu commented Oct 3, 2020

If we wanted to be clever we could take 3 arguments at a time:

open \
  '<' input.txt :input \
  '>' output.txt :output {
  while true {
    read --line :line <& $input
    write --qsn $line >& $output
  }
}

Looks kind of ugly. This is the same:

open '<' input.txt :input  { 
  open '>' output.txt :output {
    while true {
      read --line :line <& $input
      write --qsn $line >& $output
    }
  }
}

I don't really like the quoted '>' but that's what Perl does ...
We could also do r and w like:

open output.txt w :out {
  open input.txt r :in {
     ....
  }
}

@andychu
Copy link
Contributor Author

andychu commented May 14, 2021

related to #841

@andychu
Copy link
Contributor Author

andychu commented Sep 10, 2021

I think the main use case for this is the #863 fopen builtin, we can get by without it for awhile ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant