- /* if child */
- if (pid == 0) {
- /*
- * Child exec barcode program, that take input (string to encode)
- * from pipein, remapped to stdin, and write the output (a ppm
- * image) to stdout, remapped to pipeout
- */
- close(pipein[1]); /* close output side of input pipe */
- dup2(pipein[0], STDIN_FILENO); /* remap stdin in pipe input */
- close(pipeout[0]);
- dup2(pipeout[1], STDOUT_FILENO); /* remap stdout in pipe output */
- execlp("barcode", "barcode", size, NULL); //"-o", "-", NULL);
- }
- /*
- * Parent write string to pipe input and close it,
- * then wait child execution and results form pipeout,
- * then fork to convert ppm to gif using ppmtogif
- */
- close(pipein[0]); /* close input side of input pipe */
- n=write(pipein[1], argv[1], strlen(argv[1]));
- close(pipein[1]);
- waitpid(pid, NULL, 0);
- /*
- * refork to use ppmtogif
- */
- pid = fork();
- if (pid == -1) {
- WriteMess("child creation error");
- exit(0);
- }
- /*
- * second child, convert ppm to gif
- */
- if (pid == 0) {
- /* send mime type */
- close(pipeout[1]);
- dup2(pipeout[0], STDIN_FILENO);
- write(STDOUT_FILENO, content, strlen(content));
- n=read(pipeout[0], buffer, sizeof(buffer));
- printf("Letti %n di %n, %s\n", n, sizeof(buffer), buffer);
- exit(0);
- execlp("gs", "gs", "-q", "-sDEVICE=jpeg", "-sOutputFile=-", "-", NULL);
- }
- /*
- * still parent
- */
- close(pipeout[1]);
- waitpid(pid, NULL, 0);