[an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive] (none) [an error occurred while processing this directive] [an error occurred while processing this directive] [an error occurred while processing this directive][an error occurred while processing this directive]
 
[an error occurred while processing this directive] [an error occurred while processing this directive]
Skåne Sjælland Linux User Group - http://www.sslug.dk Home   Subscribe   Mail Archive   Forum   Calendar   Search
MhonArc Date: [Date Prev] [Date Index] [Date Next]   Thread: [Date Prev] [Thread Index] [Date Next]   MhonArc
 

Re: [CPROG] popen i read/write mode



"Robert Larsen" <sslug@sslug> writes:

> Jeg sidder og leger med at lægge en grafisk brugerflade på nogle
> eksisterende programmer, som kræver input fra brugeren. Til det bruger jeg
> 'popen()' funktionen, som kan åbne strømmen til programmet i enten read
> ELLER write mode.

Jeg tror du må igang med at kode selv. Noget ala følgende:

int open3(const char *file, char *const argv[], int filedes[3]) {
  int stdin[2];
  int stdout[2];
  int stderr[2];

  pipe(stdin);
  pipe(stdout);
  pipe(stderr);

  if (fork) {
    dup2(stdin[1],0);
    dup2(stdout[1],1);
    dup2(stderr[1],2);
    
    execvp(file,argv);
  }

  close(stdin[1]);
  close(stdout[1]);
  close(stderr[1]);

  filedes[0] = stdin[0];
  filedes[1] = stdout[0];
  filedes[2] = stderr[0];

  return 0;
}

Selvfølgelig med en masse fejlhåndtering. Hmmm, du har også brug for
at kunne stoppe programmet igen, det bliver lidt problematisk uden at
gmme noget mere om tilstanden.


-- 
 Peter Makholm     |       I have something to say: It's better to burn in
 sslug@sslug |                              hell, than to fade away!
 http://hacking.dk |                                             -- Kurgan


 
Home   Subscribe   Mail Archive   Index   Calendar   Search

 
 
Questions about the web-pages to <www_admin>. Last modified 2005-08-10, 20:09 CEST [an error occurred while processing this directive]
This page is maintained by [an error occurred while processing this directive]MHonArc [an error occurred while processing this directive] # [an error occurred while processing this directive] *