Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!wuarchive!emory!att!oucsboss!oucsace!tswingle From: tswingle@oucsace.cs.OHIOU.EDU (Tom Swingle) Newsgroups: comp.lang.pascal Subject: Re: Redirecting Exec() output Message-ID: <3239@oucsace.cs.OHIOU.EDU> Date: 28 Apr 91 00:51:50 GMT References: <2435@pdxgate.UUCP> Organization: Ohio University CS Dept., Athens Lines: 51 In article acolvin@youth.cavebbs.gen.nz (Aaron Colvin) writes: >mwizard@eecs.cs.pdx.edu (Craig Nelson) writes: > [ A few lines deleted, so the stupid news program will accept my article ] >> Typing: >> >> UNZIP FOO.ZIP c:\FOODIR > c:nul >> >> from the DOS prompt works like a champ. But if you use Exec() from the >> DOS unit, and set the parameters like so: >> >> Exec('UNZIP.EXE','FOO.ZIP c:\FOODIR > c:nul'); >> >> and the output is no longer redirected to nul. It appears on the screen, >> and I assure you it isn't a pretty site in the middle of a TVision program. This idea might work: exec(getenv(comspec),'/c UNZIP.EXE FOO.ZIP c:\FOODIR > nul'); Turbo Pascal's exec procedure doesn't support redirection, either in the form of redirecting output to a file or piping output to another program. However, this call says to start up a new copy of COMMAND.COM and let it run the program and handle the redirection. I have never tried it, it was just an idea that came to me as I was reading the article, but it seems to me like it should work. The disadvantage of using this is that it takes more time and memory to load and run the new command interpreter in addition to running the external program. But, short of writing your own exec procedure, it seems to be the only way to handle it within the framework of Turbo Pascal. > I then tried a cheapo type answer, I made a batch file containing the > following : > scan c: > c:\system\scanchek.txt > Again, worked fine from DOS, but from my program, instead of printing to >the screen, and ignoring the redirection, it now locks up the whole >flamin system! "Stupid thing" I said in disgust, and continued in >finishing my other Hard Drive utility program, and the unit to go with >it... The reason this might have failed, as it is a mistake I have made trying to use the exec procedure, is that you cannot call a batch file directly with exec, but you must use the same method described above, loading a copy of COMMAND.COM and telling it to run the batch file. I can't remember if this is mentioned in the documentation, but it should be. I don't have the docs handy, so I can't tell you. -- "The problem you are experiencing is | "To be sure of hitting the target, not with the network nor with the | shoot first and, whatever you hit, station. Please adjust your set." | call it the target."