Re: Stumped by open("PRN","w")
- Posted by cEnsE <cense at MAIL.RU> Jan 21, 2001
- 633 views
On Sun, 21 Jan 2001, Jim wrote: >> The following code snippet is from a Windows program using Win32Lib.ew. If I >> run it with exw.exe, on a machine with no >> printer (or anything else) attached to the parallel port, it executes the >> open("PRN","w") statement and assigns a valid >> file handle (4), where I would have expected a -1. It also continues to the >> puts(ThePrinter,line) and executes that. >> In fact, under exw, the program runs to normal completion, when I would have >> expected an abnormal termination. >> >> The very same code, copied to an .ex file, and run under ex.exe executes in >> the same way, but then crashes with a DOS >> Critical Error when it hits the puts(ThePrinter,line) statement. In both >> versions, I would have expected a -1 on the >> open for the non-existent printer. >> >> Can someone help me understand what I'm doing wrong here? >> >> Thanks. >> >> Totally perplexed. >> >> Jim >> >> ------------------- <begin code > >> object line >> integer Patterns,ThePrinter,result >> >> Patterns=open( "PATTERNS.TXT","rb" ) -- any text file of 80 >> or more char. >> if Patterns = -1 then >> result = message_box( "Open Patterns.txt FAILED in >> OnClick_ButtonPrint. Aborting. ","ERROR!", {} ) abort(1) >> >> end if >> >> ThePrinter = open("PRN","w") What exactly is this "PRN" ? the way you have it coded, if im not mistaken, the open call will open a file in the current directory called PRN. I may very well be mistaked but from a quick look over this "PRN" stands out as a possible source of your problem. >> if ThePrinter = -1 then >> result = message_box( "Unable to find a printer; skipping.", >> "ERROR!", {} ) -- never executed, although >> no printer >> else >> while 1 do >> line=gets(Patterns) >> if atom(line) then >> close(Patterns) >> close(ThePrinter) >> exit >> end if >> line=line[1..80]&"\n" >> puts(ThePrinter,line) -- processed OK under exw.exw ; >> crashes to DOS under ex.exe >> end while >> end if >> ---------< end code > I hope that helps, but if not, i tried. -- evil, corruption and bad taste ^[cense]