floyd@starsend.UUCP (Floyd Miller) (03/03/90)
I have a few batch files that run pipelined programs, searching for a pattern, extracting fields and sorting. They make life a bit easier by elliminating the need to retype long command lines. However, sometimes I want to run the final output through a pager (like "more") or save the results in a file. I try to run: filter.bat | more More doesn't do anything. So I try: filter.bat > f.out f.out gets created with no data while the output of filter.bat comes pouring out on my screen. Apparently, REDIRECTING DOESN'T WORK ON BATCH FILES. I was surprised mostly by the fact that it took up until now for me to discover this deficiency in DOS. I think that a program which overlays stderr onto stdout and then invokes the batch file would allow redirection of the batch file output. Then you would run the batch file as: redir prog.bat or redir prog.bat > file.out or redir prog.bat | more I will try this. And, if there is interest I'll post "redir" if it works. But is there an easier way? Perhaps without having to use a separate program to invoke the batch file? ******* ***************************************** ***** ************************* Floyd Miller *** *************** floyd@starsend.UUCP * ********* floyd%starsend@PRC.Unisys.com *** starsend!floyd@burdvax.PRC.Unisys.com *
floyd@starsend.UUCP (Floyd Miller) (03/11/90)
I appreciate the responses both via email and followup articles. The use of COMMAND /C certainly satisfies the problem in my original posting: redirecting the output from a batch file. The ensuing discussion on the use of the /C option with EXEC and SPAWN was also interesting. A second operation I discovered I needed was a way to redirect the stderr output. Unix shells provide the means to accomplish this but apparently not COMMAND.COM. Using the examples of EXEC to invoke COMMAND.COM from within a C program I am writing a REDIR program which will combine stderr with stdout so both can be redirected to the same place. At least that partially solves the problem. I'm not worried right now about redirecting them separately. Once I'm finished I'll submit it to C.B.I.P for posting - if I can figure out how to do that. I found a problem with the code posted for exec'ing COMMAND.COM. Using: execlp("COMMAND.COM", "/C", cmd_string, NULL); starts up COMMAND.COM interactively and results in an error message: Specified MS-DOS search directory bad. I discovered, experimentally that what is required is: execlp("COMMAND.COM", "COMMAND.COM", "/C", cmd_string, NULL); so that the 1st argument passed to COMMAND.COM is its name. I hope this helps anyone else whose had a similar problem. ******* ***************************************** ***** ************************* Floyd Miller *** *************** floyd@starsend.UUCP * ********* floyd%starsend@PRC.Unisys.com *** starsend!floyd@burdvax.PRC.Unisys.com *