Timeline for Using bi-directional popen
Current License: CC BY-SA 4.0
Post Revisions
12 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Sep 7, 2022 at 22:47 | vote | accept | Chap | ||
| Sep 7, 2022 at 22:46 | answer | added | Chap | timeline score: 1 | |
| Sep 5, 2022 at 1:03 | comment | added | Chap | @StéphaneChazelas if you want to write your observations as an answer I'll accept it. | |
| Sep 4, 2022 at 21:23 | history | edited | Chap |
add macos to tags
|
|
| Sep 4, 2022 at 20:39 | comment | added | Chap |
@StéphaneChazelas I agree it doesn't appear very useful. I decided on a quick fix and added an optional parameter to cols declaring an EOF marker which the C program sends in lieu of actual eof. Same idea as Perl's heredoc. Better would be two pipes, as you suggest.
|
|
| Sep 4, 2022 at 19:31 | comment | added | Stéphane Chazelas | Also note that if cols starts outputting something before it has finished reading its input, you may end up in a deadlock situation if the data to be processed doesn't fit whole in the pipe buffer if at the other end you don't start reading cols output until you've finished send data to it. | |
| Sep 4, 2022 at 19:25 | comment | added | Stéphane Chazelas |
If the perl program does @all_lines=<STDIN> and the print "something" then yes, it waits for EOF and you can't use popen(r+). If it does while(<STDIN>){print "something";} reading one line at a time, then you should be able to interact with it with your cols_pipe, but you'll likely still have a problem in the end if you need to signify EOF to cols and still read more output from it after that. You'd probably be better of using two pipes or a socketpair where you can shutdown directions independently. I've never used FreeBSD's popen(r+) or bidirectional pipes, they don't seem very useful
|
|
| Sep 4, 2022 at 17:57 | review | Close votes | |||
| Oct 1, 2022 at 3:05 | |||||
| Sep 4, 2022 at 17:54 | comment | added | Chap | @StéphaneChazelas I added those but it still hangs, presumably because Perl program is still waiting to read EOF. | |
| Sep 4, 2022 at 17:40 | comment | added | Stéphane Chazelas |
You'll likely also want to disable buffering in perl for the reverse direction (see perldoc -v '$|')
|
|
| Sep 4, 2022 at 17:36 | comment | added | Stéphane Chazelas |
Sounds more like a buffering issue. Maybe you need a setvbuf() on cols_pipe to disable buffering or make it line-based or call fflush() after your fprintf()
|
|
| Sep 4, 2022 at 17:32 | history | asked | Chap | CC BY-SA 4.0 |