TIP: Click on subject to list as thread! ANSI
echo: os2prog
to: Ruud Senden
from: Thomas Seeling
date: 1996-04-03 22:22:44
subject: Redirection

Hallo, Ruud!

*** Am Mittwoch 27. M„rz 1996 um 20:45 schrieb Ruud Senden an Thomas Seeling:

 RS>> Suppose I have a program which reads it's input from stdin, and
 RS>> sends it's output to stdout. A CGI-script on the WWW-server

This is how my WWW-Server now does it:


=== Cut ===
#define INCL_DOSQUEUES
#define INCL_DOSPROCESS
#define INCL_DOSFILEMGR
#include 
#include 
#include 
#include 

#define PIPESIZE 4096
#define HF_STDIN  0
#define HF_STDOUT 1

CHAR  Buf[PIPESIZE];

CHAR        LoadError[CCHMAXPATH] = {'\0'};
UCHAR       args[]="upper.exe\0test 1 2 3\0\0";
UCHAR       env[] ="PATH_INFO=/var/spool/hallo\0\0\0";
RESULTCODES ChildRC = {0,0};
PID         Child=-1;
APIRET      rc;

PID startpgm(HFILE *chin, HFILE *chout) {
  HFILE OpipeR=-1, OpipeW, IpipeR, IpipeW=-1, SaveI, SaveO, NewI, NewO;

  PSZ Arg,Env;

  Arg=args;
  Env=env;
  SaveI= -1;
  SaveO= -1;
  NewI = HF_STDIN;
  NewO = HF_STDOUT;

  IpipeR=-1;
  OpipeW=-1;

#ifdef REDIRIN
  rc = DosDupHandle(HF_STDIN, &SaveI);
  rc = DosCreatePipe(&IpipeR, &IpipeW, PIPESIZE);
  rc = DosDupHandle(IpipeR, &NewI);
#endif

#ifdef REDIROUT
  rc = DosDupHandle(HF_STDOUT, &SaveO);
  rc = DosCreatePipe(&OpipeR, &OpipeW, PIPESIZE);
  rc = DosDupHandle(OpipeW, &NewO);
#endif

  rc = DosExecPgm(LoadError,sizeof(LoadError),
    EXEC_ASYNCRESULT,Arg,Env,&ChildRC,
    (PSZ)"UPPER.EXE");
  if (rc!=0)
    fprintf(stderr,"rc (%u): %lu\n%s\n",__LINE__,rc,LoadError);

#ifdef REDIRIN
  rc = DosClose(IpipeR);
  rc = DosDupHandle(SaveI, &NewI);
  rc = DosClose(SaveI);
#endif

#ifdef REDIROUT
  rc = DosClose(OpipeW);
  rc = DosDupHandle(SaveO, &NewO);
  rc = DosClose(SaveO);
#endif

  *chin=IpipeW;
  *chout=OpipeR;
  return ChildRC.codeTerminate;
}

int main(void) {
  HFILE  Ipipe,Opipe;
  ULONG  Read=0;

  Child=startpgm(&Ipipe,&Opipe);

#ifdef REDIRIN
  strcpy(Buf,"Hallo, test!\n");

  rc=DosWrite(Ipipe,Buf,strlen(Buf),&Read);
  if (rc!=0)
    fprintf(stderr,"rc (%u): %lu\n",__LINE__,rc);
  if (strlen(Buf)!=Read)
    printf("len=%lu, written=%lu\n",strlen(Buf),Read);

  rc=DosWrite(Ipipe,Buf,strlen(Buf),&Read);
  if (rc!=0)
    fprintf(stderr,"rc (%u): %lu\n",__LINE__,rc);
  if (strlen(Buf)!=Read)
    printf("len=%lu, written=%lu\n",strlen(Buf),Read);

  rc=DosClose(Ipipe);
  if (rc!=0)
    fprintf(stderr,"rc (%u): %lu\n",__LINE__,rc);
#endif

#ifdef REDIROUT
  do {
    rc=DosRead(Opipe, Buf, sizeof(Buf), &Read);
    if (rc!=0)
      fprintf(stderr,"rc (%u): %lu\n",__LINE__,rc);
    if (Read>0) {
      printf("got: %lu\n",Read);
    }
  } while (Read);
  DosClose(Opipe);
#endif

  printf("Wait for Child %lu.\n",Child);
  rc=DosWaitChild(DCWA_PROCESS,DCWW_WAIT,&ChildRC,&Read,Child);
  if (rc!=0)
    fprintf(stderr,"rc (%u): %lu\n",__LINE__,rc);
  printf("Child %lu terminated, reason=%lu, rc=%lu.\n",
  Read,ChildRC.codeTerminate,ChildRC.codeResult);

  return 0;
}
=== Cut ===


Tschau...Thomas

--- E3-32/1.11-32/2.50+
* Origin: Die TeX-Box +49-6034-1455 V.34 -930022 ISDN 24h (2:244/1130.42)
SEEN-BY: 50/99 78/0 270/101 620/243 711/401 409 410 413 430 808 809 934 955
SEEN-BY: 712/407 515 517 628 713/888 800/1 7877/2809
@PATH: 244/1130 24/999 2/777 396/1 270/101 712/515 711/808 809 934

SOURCE: echomail via fidonet.ozzmosis.com

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.