- close(pipein[1]); /* close output side of input pipe */
- dup2(0, pipein[0]); /* remap stdin in pipe input */
- close(pipeout[0]); /* close input side of output pipe */
- dup2(1, pipeout[1]); /* remap stdout in pipe output */
- execlp("barcode", "barcode", "-E", NULL);
- } else {
- /* first set the pipe */
- close(pipein[0]); /* close input side of input pipe */
- close(pipeout[1]); /* close output side of output pipe */
- write(pipein[1], argv[1], strlen(argv[1]));
- close(pipein[1]);
- waitpid(pid, NULL, 0);
- pid = fork();
- if (pid == -1) {
- WriteMess("child creation error")
- exit(0);
- }
- if (pid == 0) {
- /* send mime type */
- write(0,content, strlen(content));
- dup2(0, pipeout[0]);
- execlp("gs", "gs", "-sDEVICE=jpeg", "-sOutputFile=-", "-", NULL);
- } else {
- close(pipeout[0]);
- waitpid(pid, NULL, 0);
- }
+ close(pipein[1]); /* close pipe write end */
+ dup2(pipein[0], STDIN_FILENO); /* remap stdin to pipe read end */
+ close(pipeout[0]);
+ dup2(pipeout[1], STDOUT_FILENO); /* remap stdout in pipe output */
+ execlp("barcode", "barcode", size, NULL); //"-o", "-", NULL);
+ }
+ close(pipein[0]); /* close input side of input pipe */
+ write(pipein[1], argv[1], strlen(argv[1])); /* write parameter to pipe */
+ close(pipein[1]); /* closing write end */
+ waitpid(pid, NULL, 0); /* wait child completion */
+ /* Second fork: use child to run ghostscript */
+ if ( (pid = fork()) == -1) { /* on error exit */
+ WriteMess("child creation error");
+ exit(0);
+ }
+ /* second child, convert PS to JPEG */
+ if (pid == 0) {
+ close(pipeout[1]); /* close write end */
+ dup2(pipeout[0], STDIN_FILENO); /* remap read end to stdin */
+ /* send mime type */
+ write(STDOUT_FILENO, content, strlen(content));
+ execlp("gs", "gs", "-q", "-sDEVICE=jpeg", "-sOutputFile=-", "-", NULL);