-
Notifications
You must be signed in to change notification settings - Fork 368
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
[ new ] Add support for bi-directional pipes on POSIX systems (resolves #2935) #2944
Conversation
Thanks for this! It was on my TODO list for this week, so thanks for checking this item off. |
I have had a quick look at the code, it was more easier than I imagined. Kudos. I do have a minor quibble. I wonder if a small layer of encapsulation should be added.
Then again that could be a bit OTT for such a low-level process API. |
👍 I think it's a good idea to break the symmetry in the type. The example was confusing to me as I understood in/out to be from the POV of the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm still reading over the C code but I do think we should add a test that touches this new code prior to merging as well.
I was thinking something along the lines of: ||| Result of a popen2 command, containing the
public export
record SubProcess where
constructor MkSubProcess
||| Process id of the spawned process
pid : Int
||| The input stream of the spawned process
input : File
||| The output stream of the spawned process
output : File Where The |
RE having use of the PID, even without wait and kill we already have the ability to send signals to it exposed in the base lib. [EDIT] more accurately, kill is already exposed, but under the name |
I switched it over to a Record, added a test case, and got it working on windows. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice. Thanks!
[ re #2944, fix ] Make `popen2` be able to not to leak system resources
Description
Adds a
popen2
function toSystem.File.Process
which allows Idris to run subprocesses with access to both the input and output file streams. It currently doesn't support windows, but updates are welcome if it's possible and somebody knows how to do it (and can verify that it works). This feature was requested by @jfdm in #2935, and I think @ohad was asking about it last year.With this change you can do:
But I'd recommend writing be done on a separate thread from reading to avoid deadlocking if the subprocess is waiting for a reader while we're waiting to write.
Let me know if any changes are needed.
Should this change go in the CHANGELOG?
Yes, I added a note to the CHANGELOG.