English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. C/C++

 
 
Thread Tools
Old 06 February 2017, 18:26   #1
alkis
Registered User
 
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
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;
}
So Program A, reads from stdin and if you happen to enter an integer it doubles it and outputs the result and stays in the loop. (Well, if you type "quit" it ends)

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?
Attached Files
File Type: zip foo.zip (4.8 KB, 78 views)
alkis is offline  
Old 07 February 2017, 09:19   #2
idrougge
Registered User
 
Join Date: Sep 2007
Location: Stockholm
Posts: 4,334
I think the real Amiga way is to use a MessagePort.
idrougge is offline  
Old 07 February 2017, 18:22   #3
alkis
Registered User
 
Join Date: Dec 2010
Location: Athens/Greece
Age: 53
Posts: 719
Quote:
Originally Posted by idrougge View Post
I think the real Amiga way is to use a MessagePort.
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 ;-)
alkis is offline  
 


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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 07:31.

Top

Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2024, vBulletin Solutions Inc.
Page generated in 0.07134 seconds with 16 queries