Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!spool.mu.edu!news.cs.indiana.edu!maytag!watstat.waterloo.edu!dmurdoch From: dmurdoch@watstat.waterloo.edu (Duncan Murdoch) Newsgroups: comp.lang.pascal Subject: Re: Redirecting I/O for .BAT files? Message-ID: <1991Jun20.123522.10793@maytag.waterloo.edu> Date: 20 Jun 91 12:35:22 GMT Article-I.D.: maytag.1991Jun20.123522.10793 References: <45670020@hpcupt3.cup.hp.com> <45670022@hpcupt3.cup.hp.com> Sender: news@maytag.waterloo.edu (News Owner) Organization: University of Waterloo Lines: 32 In article <45670022@hpcupt3.cup.hp.com> defaria@hpcupt3.cup.hp.com (Andy DeFaria) writes: > >Begin { Foo } > Exec ('D:\COMMAND.COM', 'D:\COMMAND.COM /C C:\ANDY\FOO.BAT > FOO.OUT'); > Writeln ('DOSError = ', DOSError); ... > >When this is run I see: > >Specified COMMAND search directory bad >DOSError = 0 > >written to the screen and in examining FOO.OUT I find simply: > >DOSError = 2 > >Now what am I doing wrong? You forgot a /C at the start of the command line. It should be Exec ('D:\COMMAND.COM', '/C D:\COMMAND.COM /C C:\ANDY\FOO.BAT > FOO.OUT'); The first /C tells the first command processor that what follows is a command, and the second one tells the second processor that the batch file is a command. I think the first command processor is the one that sees and acts on the '> FOO.OUT', so that the second command processor already has STDOUT redirected. A possibly simpler way to achieve the same thing is to use the FORCDUP DOS call to redirect STDOUT into a file. That method can also be used to redirect STDERR, if you want to do that. Duncan Murdoch