boileau
boileau

Reputation: 817

How to "disable" a file output stream

I'm working on some legacy code in which there are a lot of WriteLn(F, '...') commands scattered pretty much all over the place. There is some useful information in these commands (what information variables contain, etc), so I'd prefer not to delete it or comment it out, but I want to stop the program from writing the file.

Is there any way that I can assign the F variable so that anything written to it is ignored? We use the console output, so that's not an option.

Upvotes: 1

Views: 324

Answers (2)

No'am Newman
No'am Newman

Reputation: 6477

Going back a long long time to the good old days of DOS - If you assign 'f' to the device 'nul', then there should be no output.

assign (f, 'nul')

I don't know whether this still works in Windows.

Edit: You could also assign 'f' to a file - assignfile (f, 'c:\1.txt') - for example.

Upvotes: 4

supercat
supercat

Reputation: 81257

Opening the null device and letting output go there would probably work. Under DOS, the performance of the NUL device was astonishingly bad IIRC (from what I understand, it wasn't buffered, so the system had to look up NUL in the device table when processing each byte) but I would not be at all surprised if it's improved under newer systems. In any case, that's probably the easiest thing you can do unless you really need to maximize performance. If performance is critical, it might in theory be possible to override the WriteLn function so it does nothing for certain files, but unfortunately I believe it allows syntax forms that were not permissible for any user-defined functions.

Otherwise, I would suggest doing a regular-expression find/replace to comment out the WriteLn statements in a fashion that can be mechanically restored.

Upvotes: 0

Related Questions