Hello,
I'm working on an application that is essential a front-end to a command line program if you will. Basically my program (A) uses another program (B) to perform a few tasks. A launches B when it needs to do the tasks, passing data via command line arguments and an anonymous pipe (B's stdin) -- reading back info over another pipe (B's stdout). However I'm aiming to have this program portable, at least Windows and Linux (I'm using Gtk for my UI).
So my question is, is there any portable pipe API? Or should I wrap Linux pipes and Windows anonymous pipes? If so, it'd be pretty hard to ensure they had the same behaviour. I ask because I don't want to reinvent the wheel, I've already looked into it but came up dry.
My wrap idea sortof goes like:
Code:
#ifdef WIN32
#define WIN32_LEAN_AND_MEAN
#include <windows.h>
#endif
#ifdef LINUX
/* includes */
#endif
#include <stdio.h>
#include <stdlib.h>
int apipe_connect(struct apipe_t * p, const char * cmd)
{
#ifdef WIN32
/* error */
if(CreatePipe(&(p->hRead), &(p->hWrite), NULL, 40) == 0)
return 1;
#endif
return 0;
}
int apipe_disconnect(struct apipe_t * p)
{
#ifdef WIN32
CloseHandle(p->hRead);
CloseHandle(p->hWrite);
#endif
#ifdef LINUX
/* linux ... */
#endif
return 0;
}
Would that be the 'best' way to get my API working on Linux/Windows? (ie use of the pre-processor)... Or would it be better to put the 'WIN32' stuff in one file, ditto for the 'LINUX' stuff and include the files accordingly? Then I'd have to sync my API if it changed?