mwizard@eecs.cs.pdx.edu (Craig Nelson) (04/21/91)
OK,OK,OK... I finally found something in TP 6.0 that I couldn't figure out. Supposedly anything you execute from a DOS prompt should execute the same from an Exec() call, so long as no direct video memory calls are made... Well, I want to suppress output of a program that does not use direct video memory, specificly, UNZIP.EXE . Now the weird part. 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. Any ideas out there ? Cheers!, and TIA. []====================================================================[] || Craig R. Nelson | CCSofD Software Inc. || || Programmer | Beaverton, OR, 97005 || || mwizard@eecs.ee.pdx.edu | (unlisted on the net) ||
nate@neutron.lcs.mit.edu (04/22/91)
Craig, If you use the CRT unit, then redirection will not work unless you do: assign(output,''); rewrite(output); i. (ignore i. above) ... close(output); This might be an answer... I have not tried it. good luck... nate liskov
cs202216@umbc5.umbc.edu (cs202216) (04/22/91)
In article <2435@pdxgate.UUCP> mwizard@eecs.cs.pdx.edu (Craig Nelson) writes: > > OK,OK,OK... I finally found something in TP 6.0 that I couldn't >figure out. Supposedly anything you execute from a DOS prompt should >execute the same from an Exec() call, so long as no direct video memory >calls are made... Well, I want to suppress output of a program that >does not use direct video memory, specificly, UNZIP.EXE . Now the weird >part. 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. > >Any ideas out there ? > >Cheers!, and TIA. > > []====================================================================[] > || Craig R. Nelson | CCSofD Software Inc. || > || Programmer | Beaverton, OR, 97005 || > || mwizard@eecs.ee.pdx.edu | (unlisted on the net) || Try Exec(getenv('COMSPEC'),'/c unzip.exe FOO.ZIP c:\FOODIR > c:nul'); -- Program Signature(input,output); const internet = 'cs202216@umbc5.umbc.edu'; name = 'Matt Gove';
Harold.Ruby@f1999.n106.z1.fidonet.org (Harold Ruby) (04/22/91)
on 19 Apr 91 23:30:28 Craig Nelson said to All >part. Typing: > > UNZIP FOO.ZIP c:\FOODIR > c:nul > > Exec('UNZIP.EXE','FOO.ZIP c:\FOODIR > c:nul'); > >and the output is no longer redirected to nul. It appears >on the screen, I don't understand the logic behind assigning a drive location for NUL. NUL requires no path/drive. Also, I've always re-directed output (from dos, and EXEC statements) by using : ">+FILENAME" -not- ">+(space)+FILENAME" as you have done. Try this: Exec ('UNZIP.EXE','FOO.ZIP c:\FOODIR >NUL'); Harold
acolvin@youth.cavebbs.gen.nz (Aaron Colvin) (04/27/91)
mwizard@eecs.cs.pdx.edu (Craig Nelson) writes: > OK,OK,OK... I finally found something in TP 6.0 that I couldn't > figure out. Supposedly anything you execute from a DOS prompt should > execute the same from an Exec() call, so long as no direct video memory > calls are made... Well, I want to suppress output of a program that > does not use direct video memory, specificly, UNZIP.EXE . Now the weird > part. 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. Likewise, I have found the exact same prob when trying to redirect scan to a textfile, and the run a prog that ran through that text file and check for errors (it was automated in DESQview, and if a virus was found then it would beep furiously and shut down the system! and if not I wouldnt even no its running), but unfortunately I couldnt get it to go, and it wasnt necessary, as I had just downloaded the latest version of VShield v76c ... but as you say the redirection doesnt work at all and just goes straight to the screen, ignoring everything after the '>' .. 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... So, I wouldnt mind figuring this out, even if it is just for knowledges sake, as I have no need for that program anymore...'vshield' does a fine job! :-) Cheers all.. -- acolvin@youth.cavebbs.gen.nz (Aaron Colvin) My Opinions, Are Just That, *My* Opinions...
bkirby@mcs213f.cs.umr.edu (Bill Kirby) (04/27/91)
In article <26614@adm.brl.mil> nate@neutron.lcs.mit.edu writes: >Craig, > > If you use the CRT unit, then redirection will not work >unless you do: > > assign(output,''); > rewrite(output); >i. >(ignore i. above) > > ... > close(output); > > This might be an answer... I have not tried it. > >good luck... nate liskov 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, +--------------------------+-----------------------------------------------+ | Bill Kirby | Internet: bkirby@cs.umr.edu | | Computer Science Dept. | Bitnet: bkirby%cs.umr.edu@umrvmb.bitnet | | University of MO - Rolla | UUCP: ...!uunet!cs.umr.edu!bkirby | | Rolla, MO 65401 | | +--------------------------+-----------------------------------------------+
jonathan@thevoid.fidonet.org (Jonathan Bradshaw) (04/28/91)
In a message of <Apr 26 17:41>, Aaron Colvin (acolvin@youth.cavebbs.gen.nz ) writes: > 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. Argh, you overlooked something a little obvious. Redirection via ">" is part of COMMAND.COM and your bypassing it using the above. You'll need to do something like: Exec('COMMAND.COM', '/c UNZIP.EXE FOO.ZIP C:\FOODIR > NUL'), but PLEASE don't hard code COMMAND.COM since alot of us use 4DOS.COM --- instead use the EnvrStr('COMSPEC') to get the name of the command interpreter. If you don't want to use COMMAND.COM you need to write your own routines to redirect StdOut. -- Jonathan Bradshaw | Internet: jonathan%thevoid@nstar.rn.com - U93 WNDU-FM South Bend (92.9FM) | -OR- jonathan@thevoid.fidonet.org - Forsythe Computers, South Bend | UUCP: ...!uunet!nstar!thevoid!jonathan `The Voidian Gateway of Michiana' | Fidonet: 1:227/1.6 Prodigy: XMSN02B "...anyone can beat the odds if they have the will..." - Debster [DGIF#9588]
tswingle@oucsace.cs.OHIOU.EDU (Tom Swingle) (04/28/91)
In article <FoR113w164w@youth.cavebbs.gen.nz> 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."
sdalelt@cc.curtin.edu.au (04/29/91)
In article <2435@pdxgate.UUCP>, mwizard@eecs.cs.pdx.edu (Craig Nelson) writes: > 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. DOS performs the re-direction for you! You'll need to spawn a command processor in order for the redirection to work! ie. exec(getenv('COMSPEC'),'UNZIP.EXE FOO.ZIP C:\FOODIR > nul'); Cheers, Lincoln. _____________________________________________________________________________ Internet: sdalelt@cc.curtin.edu.au Voice: +61-9-459-4701 lincoln_dale@f627.n690.z3.fidonet.org FidoNet: Lincoln Dale @ 3:690/627.0 Data: +61-9-493-1534 PSImail: psi%050529452300070::sdalelt +61-9-493-2625 UUCP: uunet!munnari.oz!cc.curtin.edu.au!sdalelt Bitnet: sdalelt%cc.curtin.edu.au@cunyvm.bitnet
tswingle@oucsace.cs.OHIOU.EDU (Tom Swingle) (04/30/91)
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."
dave@tygra.Michigan.COM (David Conrad) (06/10/91)
In article <15253@ms.maus.de> Kai_Henningsen@ms.maus.de (Kai Henningsen) writes: >the following works absolutely flawless: > >{$M 16384,0,0} >program tst; >uses dos; >begin > swapvectors; > exec(getenv('COMSPEC'),'/c dir >somewhere'); > swapvectors; ~~~~~~~~~ >end. > >Now, if you cannot get THIS program to run, something is wrong with DOS - There certainly is something wrong with DOS - it only allows 8 character file names. I'm sure you knew that, but I just wanted to head off any complaints about the output being sent to file 'somewher' instead of 'somewhere', and Turbo Pascal deleting the last character of the string. I also can't pass up a chance to flame MS-DOS. ;-) -- David R. Conrad dave@michigan.com -- = CAT-TALK Conferencing Network, Computer Conferencing and File Archive = - 1-313-343-0800, 300/1200/2400/9600 baud, 8/N/1. New users use 'new' - = as a login id. AVAILABLE VIA PC-PURSUIT!!! (City code "MIDET") = E-MAIL Address: dave@Michigan.COM