- /* convert PDF to JPEG */
- file1 = popen("gs -q -sDEVICE=jpeg -sOutputFile=- -", "w");
- /* convert EPS to PDF*/
- dup2(fileno(file1), STDOUT_FILENO); /* set epstopdf stdout to file1 */
- file2 = popen("epstopdf --filter", "w");
-// file2 = popen("eps2eps", "w");
- /* create barcode */
- dup2(fileno(file2), STDOUT_FILENO); /* set barcode stdout to file2 */
- file3 = popen("barcode -E", "w");
- write(fileno(file3), argv[1], strlen(argv[1]));
+ /* execute chain of command */
+ for (i=0; i<4; i++) {
+ pipe[i] = popen(cmd_string[i], "w");
+ dup2(fileno(pipe[i]), STDOUT_FILENO);
+ }
+ /* create barcode (in PS) */
+ pipein = popen("barcode", "w");
+ /* send barcode string to barcode program */
+ write(fileno(pipein), argv[1], strlen(argv[1]));
+ pclose(pipein);
+ /* close all pipes (in reverse order) */
+ for (i=4; i==0; i--) {
+ pclose((pipe[i]));
+ }