06 February 2017, 18:26 | #1 |
Registered User
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 725
|
Pipe both stdin and stdout from a sub-process
I have a program A that is in a forever (kind of) I/O loop. Reads stdin, and prints results in stdout.
I want program B to start program A and send it input and read it's output. Let me give some samples Program A Code:
#include <stdio.h> #include <string.h> int main(int argc, char *argv[]) { char buf[80]; int val; while (fgets(buf, 80, stdin)) { if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = '\0'; if (!strcmp(buf, "quit")) break; val = atol(buf); printf("%d\n", val+val); fflush(stdout); } printf("Something happened\n"); return 0; } Researching for the problem seems like the way to go is to open two pipes on the sub-process. Use one for sending to stdin, and use the other to read from stdout (of the sub-process). So, I started from libnix's popen and tried to extend it so it opens two pipes. The thing that fails is reading from sub-process output. It seems to never send anything to that pipe. In the archive you'll find three files. simple.c is standalone (m68k-amigaos-gcc -o simple simple.c) drive2.c test.c should compile together (m68k-amigaos-gcc -o test drive2.c test.c) Finally test should send input to simple and read it's output. How should I tackle this? Maybe some other way? |
07 February 2017, 09:19 | #2 |
Registered User
Join Date: Sep 2007
Location: Stockholm
Posts: 4,357
|
I think the real Amiga way is to use a MessagePort.
|
07 February 2017, 18:22 | #3 |
Registered User
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 725
|
True that. It's just that I might need to handle an "amiga unaware" application. For instance, a uci chess engine https://github.com/alexalkis/sillychess ;-)
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Pipe Mania (Empire) | Avanze | MarketPlace | 0 | 11 April 2016 21:39 |
\\.\pipe\WinUAE | boir | support.WinUAE | 17 | 23 October 2015 08:57 |
Length of CON/stdin buffer? | idrougge | Coders. Scripting | 4 | 12 October 2015 15:32 |
Amiga, vfork(), and pipe() | tygre | Coders. General | 5 | 03 December 2011 01:35 |
Which gamemap should i process next...?? | Joe Maroni | HOL contributions | 35 | 10 July 2008 05:36 |
|
|