Index: esh.c
===================================================================
--- esh.c	(revision 333512)
+++ esh.c	(working copy)
@@ -133,6 +133,7 @@
 int		debug;
 int		piping;
 FILE	*infp;
+FILE	*outfp;
 #ifdef __QNXNTO__
 	struct inheritance inherit;
 #else
@@ -664,14 +665,23 @@
 
 	if(argv[0] == NULL  ||  strlen(argv[0]) == 0)
 		return(EOK);
+	
+	if (iov[1]!=-1){
+		outfp = fdopen(iov[1], "w");
+		if (outfp==NULL)
+			perror("unable to redirect");
+	}
+	if (outfp == NULL)
+		outfp = stdout;
 
+
 #ifndef EMBEDDED
 	if(strcmp(argv[0], "alias") == 0) {
 
 		if(argv[1] == NULL) {
 			for(n = 0 ; n < MAX_ALIAS ; ++n)
 				if(alias[n])
-					printf("%s\n", alias[n]);
+					fprintf(outfp,"%s\n", alias[n]);
 			return(EOK);
 			}
 			
@@ -732,7 +742,7 @@
 		if(argv[1] == NULL  ||  argv[1][0] == '-')
 dump_env:
 			for(n = 0 ; environ[n] ; ++n)
-				printf("%s\n", environ[n]);
+				fprintf(outfp,"%s\n", environ[n]);
 		else {
 			if(restrict)
 				return(EPERM);
@@ -802,7 +812,7 @@
 		if(getcwd(cmdline, UTIL_PATH_MAX) == NULL)
 			return(errno);
 
-		printf("%s\n", cmdline);
+		fprintf(outfp,"%s\n", cmdline);
 		return(EOK);
 		}
 
@@ -812,8 +822,9 @@
 	if(strcmp(argv[0], "print") == 0) {
 #endif
 		for(n = 1 ; argv[n] ; ++n)
-			printf("%s%s", n > 1 ? " " : "", argv[n]);
-		printf("\n");
+				fprintf(outfp,"%s%s",n>1?" ":"",argv[n]);
+			
+		fprintf(outfp, "\n");
 
 		return(EOK);
 		}
@@ -1039,11 +1050,11 @@
 		
 		for(n = 1 ; qnx_psinfo(0, n, &data, 0, 0) != -1 ; n = data.pid + 1)
 			if(data.flags & _PPF_MID)
-				printf("Proxy   %5d\n", data.pid);
+				fprintf(outfp,"Proxy   %5d\n", data.pid);
 			else if(data.flags & _PPF_VID)
-				printf("VC      %5d\n", data.pid);
+				fprintf(outfp,"VC      %5d\n", data.pid);
 			else
-				printf("Process %5d %s\n", data.pid, data.un.proc.name);
+				fprintf(outfp,"Process %5d %s\n", data.pid, data.un.proc.name);
 
 		return(EOK);
 		}
@@ -1063,8 +1074,8 @@
 		if(argv[1]  &&  (fd = open(argv[1], 0)) != -1) {
 			if(disk_get_entry(fd, &d_bfr) == 0  &&  disk_space(fd, &free, &total) == 0) {
 				used = total - free;
-				printf("Name                 Total      Used      Free  Percent\n");
-				printf("%-16s %8dK %8dK %8dK    %d%%\n",
+				fprintf(outfp,"Name                 Total      Used      Free  Percent\n");
+				fprintf(outfp,"%-16s %8dK %8dK %8dK    %d%%\n",
 						argv[1], total/2, used/2, free/2, (used*100)/total);
 
 				close( fd );
@@ -1096,11 +1107,11 @@
 			}
 			used = buff.f_blocks - buff.f_bfree;
 
-			printf("Name                 Total      Used      Free  Percent   Type\n");
+			fprintf(outfp,"Name                 Total      Used      Free  Percent   Type\n");
 #if _FILE_OFFSET_BITS-0 == 64
-			printf("%-16s %8lldK %8lldK %8lldK    %3lld%%    %s\n",
+			fprintf(outfp,"%-16s %8lldK %8lldK %8lldK    %3lld%%    %s\n",
 #else
-			printf("%-16s %8dK %8dK %8dK    %3d%%    %s\n",
+			fprintf(outfp,"%-16s %8dK %8dK %8dK    %3d%%    %s\n",
 #endif
 					argv[1], buff.f_blocks, used, buff.f_bfree, (used*100)/buff.f_blocks, buff.f_basetype);
 			return(EOK);
@@ -1195,6 +1206,7 @@
 #endif
 
 	infp = stdin;
+	outfp = stdout;
 
 	signal(SIGINT, SIG_IGN);
 #ifdef __QNXNTO__
@@ -1458,6 +1470,8 @@
 				}
 			}
 
+		if (iov[1]!=-1)
+			fflush(outfp);
 		for(n = 0 ; n < 3 ; ++n)
 			if(iov[n] != -1)
 				close(iov[n]);
