Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!att!oucsboss!oucsace!tswingle From: tswingle@oucsace.cs.OHIOU.EDU (Tom Swingle) Newsgroups: comp.lang.pascal Subject: Re: Redirecting Exec() output Message-ID: <3249@oucsace.cs.OHIOU.EDU> Date: 29 Apr 91 20:28:51 GMT References: <26614@adm.brl.mil> <2684@umriscc.isc.umr.edu> Followup-To: comp.os.msdos.programmer Organization: Ohio University CS Dept., Athens Lines: 71 In article <2684@umriscc.isc.umr.edu> bkirby@mcs213f.cs.umr.edu (Bill Kirby) writes: >In article <26614@adm.brl.mil> nate@neutron.lcs.mit.edu writes: >>Craig, >> [ CRT unit discussion deleted ] >I posted a reply to the original question, but I have not seen it here >yet. I am having the same problem. > >In any case, the above code is not relevant to our problem. Yes, you >need to open the file as described above if you want your pascal program >to output to standard out. We want to Exec a program from within >pascal and have the output redirected to a file. > >For instance, suppose I have a program HELLO.EXE (not necessarily >written in pascal) which outputs "hello, world" to standard out. >At the DOS prompt I can type "HELLO > OUTPUT.TXT" and a file >OUTPUT.TXT will be created containing the text "hello, world". > >Now, if you try the following from within a pascal program: > > Exec("COMMAND.COM","/C HELLO.EXE > OUTPUT.TXT"); > >it should produce the exact same results, but it doesn't. >Redirecting INPUT in this manner works fine. > >Am I doing something wrong? > >BTW, I'm using Turbo 6.0. > >Thanks, I think the problem lies in the fact that Turbo Pascal removes all references to redirection since it is not set up to support redirection. I had posted a solution like the one above but now that someone has tested and mentions that it does not work, I think I see why. Turbo Pascal sees the line Exec("COMMAND.COM","/C HELLO.EXE > OUTPUT.TXT"); and sees that it is a command being executed with redirection. Since Turbo Pascal doesn't support redirection, it removes the redirection so the line becomes Exec("COMMAND.COM","/C HELLO.EXE"); If you could trick Turbo into passing the "> OUTPUT.TXT" to Dos, you could probably get this to work, but I don't know of any way to do it. One solution posted was to create a DUMMY.BAT file containg the line HELLO > OUTPUT.TXT and use the line Exec(getenv('comspec'),"/c DUMMY.BAT"); of course, this is a very poor programming solution because anyone using your program would have to have DUMMY.BAT in the current directory or in the PATH, and if you wanted to change the program being executed you would have to change the .BAT file; it would not be a very self-contained solution. The only other thing I can tell you is to see if someone has written an EXEC procedure supporting redirection, or if you are familiar with how it is done, write it yourself. I'm not familiar enough to know how this is done. Perhaps you could post this question to comp.os.msdos.programmer and they would be more helpful. I am redirecting :-) followups there so that it might be likely to get an answer. -- "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."