[xiph-commits] r12596 - trunk/ezstream/src

moritz at svn.xiph.org moritz at svn.xiph.org
Wed Feb 28 17:22:08 PST 2007


Author: moritz
Date: 2007-02-28 17:22:06 -0800 (Wed, 28 Feb 2007)
New Revision: 12596

Modified:
   trunk/ezstream/src/ezstream.c
Log:
Redirect only de-/encoder screen output to /dev/null with -q, and restore
standard error outside that popen() call.


Modified: trunk/ezstream/src/ezstream.c
===================================================================
--- trunk/ezstream/src/ezstream.c	2007-03-01 00:34:57 UTC (rev 12595)
+++ trunk/ezstream/src/ezstream.c	2007-03-01 01:22:06 UTC (rev 12596)
@@ -506,10 +506,27 @@
 	*popenFlag = 0;
 	if (pezConfig->reencode) {
 		if (strlen(extension) > 0) {
+			int	stderr_fd = dup(STDERR_FILENO);
+
 			pCommandString = buildCommandString(extension, fileName, pMetadata);
 			if (vFlag > 1)
 				printf("%s: Running command `%s`\n", __progname,
 				       pCommandString);
+
+			if (qFlag) {
+				int fd;
+
+				if ((fd = open(_PATH_DEVNULL, O_RDWR, 0)) == -1) {
+					printf("%s: Cannot open %s for redirecting STDERR output: %s\n",
+					       __progname, _PATH_DEVNULL, strerror(errno));
+					exit(1);
+				}
+
+				dup2(fd, STDERR_FILENO);
+				if (fd > 2)
+					close(fd);
+			}
+
 			fflush(NULL);
 			errno = 0;
 			if ((filep = popen(pCommandString, "r")) == NULL) {
@@ -527,6 +544,9 @@
 #endif
 			}
 			xfree(pCommandString);
+
+			if (qFlag)
+				dup2(stderr_fd, STDERR_FILENO);
 		} else
 			printf("%s: Error: Cannot determine file type of '%s'.\n",
 			       __progname, fileName);
@@ -1085,20 +1105,6 @@
 	}
 #endif /* HAVE_SIGNALS */
 
-	if (qFlag) {
-		int fd;
-
-		if ((fd = open(_PATH_DEVNULL, O_RDWR, 0)) == -1) {
-			printf("%s: Cannot open %s for redirecting STDERR output: %s\n",
-			       __progname, _PATH_DEVNULL, strerror(errno));
-			return (1);
-		}
-
-		dup2(fd, STDERR_FILENO);
-		if (fd > 2)
-			close(fd);
-	}
-
 	if (shout_open(shout) == SHOUTERR_SUCCESS) {
 		int	ret;
 		char	*tmpFileName, *p;



More information about the commits mailing list