[zeromq-dev] [czmq] API design of zproc_run

Michal Vyskocil michal.vyskocil at gmail.com
Sun Mar 19 10:07:07 CET 2017


I have finished a first draft of zproc class for czmq. It should provide
nice and easy to use API to execute and communicate with subcommands. I was
inspired by Python https://docs.python.org/3/library/subprocess.html
module. zproc use zeromq sockets to pass data in or from the subprocess.
That means that the concept of unix pipes now runs through any libzmq
transport well :)

Right now it works for libzmq4 and Linux and OSX.
I tried to make API simple and easy to use and to provide zproject API
model from start. The problem is zproc_run. Right now I simply copy execve
from unix, so the prototype look this way.

int zproc_run (zproc_t *self, const char *filename, char *const
argv[], char *const envp[])


There are three problems

   1. Incompatible with API model
   2. Does not look really nice to me
   3. argv [0] is different from filename, so developer must not forget to
   pass at least something as argv.


Given my knowledge of czmq API, I'd say the best way to go is to

//  Adds an argument to process command line
void zproc_arg (zproc_t *self, const char *format, ...);

//   Adds an enviroment variable for a process
void zproc_env (zproc_t *self, const char *key, const char *format, ...);

// Execute the subprocess, return -1 if execution fails
int zproc_run ();

So the sample usage would be

zproc_t *cat = zproc_new ();
zproc_arg (self, "%s", "cat");              // Note that filename and
argv[0] are two distincs things
zproc_arg (self, "%s", "-A");
zproc_arg (self, "%s", "/etc/passwd");

zproc_env (self, "LC_ALL", "%s", "C");
zproc_run ();

However I am not convinced if this is the best API ever. And I still did
not solved argv[0] problem. Are there any ideas for better API?

best regards
     Michal Vyskocil
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20170319/6f39b658/attachment.htm>

More information about the zeromq-dev mailing list