www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Write to stdin, read from stdout of a spawn command (a library)

reply Victor Porton <porton narod.ru> writes:
I want to write to stdin and read from stdout of an OS command I 
spawn without deadlocks. (I have a string to write to stdin and 
want to read its stdout as a string.)

Is there a ready D library for this?

I wrote a C library for this and consider to port to D (either as 
bindings or as a rewrite):

https://github.com/vporton/libcomcom
Jan 23 2019
next sibling parent reply Victor Porton <porton narod.ru> writes:
On Wednesday, 23 January 2019 at 22:51:45 UTC, Victor Porton 
wrote:
 I want to write to stdin and read from stdout of an OS command 
 I spawn without deadlocks. (I have a string to write to stdin 
 and want to read its stdout as a string.)

 Is there a ready D library for this?

 I wrote a C library for this and consider to port to D (either 
 as bindings or as a rewrite):

 https://github.com/vporton/libcomcom
By the way, is it worth to rewrite this using fibers? Fibers have the advantage that it becomes possible to run several spawn commands simultaneously. However, I suspect that usage of fibers may make the code even less efficient than the current approach which passes input and output as one string write/read operation, without any split of data into several I/O operations. What do you think?
Jan 23 2019
parent Jon Degenhardt <jond noreply.com> writes:
On Wednesday, 23 January 2019 at 23:23:47 UTC, Victor Porton 
wrote:
 On Wednesday, 23 January 2019 at 22:51:45 UTC, Victor Porton 
 wrote:
 I want to write to stdin and read from stdout of an OS command 
 I spawn without deadlocks. (I have a string to write to stdin 
 and want to read its stdout as a string.)

 Is there a ready D library for this?

 I wrote a C library for this and consider to port to D (either 
 as bindings or as a rewrite):

 https://github.com/vporton/libcomcom
By the way, is it worth to rewrite this using fibers? Fibers have the advantage that it becomes possible to run several spawn commands simultaneously. However, I suspect that usage of fibers may make the code even less efficient than the current approach which passes input and output as one string write/read operation, without any split of data into several I/O operations. What do you think?
You've probably looked at std.process (https://dlang.org/phobos/std_process.html), but in case not, take a look, it may contain the building blocks you need. --Jon
Jan 23 2019
prev sibling parent Kagamin <spam here.lot> writes:
See also http://libpipeline.nongnu.org/
Jan 23 2019