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:
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?
/* includes */
int apipe_connect(struct apipe_t * p, const char * cmd)
/* error */
if(CreatePipe(&(p->hRead), &(p->hWrite), NULL, 40) == 0)
int apipe_disconnect(struct apipe_t * p)
/* linux ... */