# Write to /dev/null?

I'm working on package that (among other things) writes an external file during compilation. I'd like to provide an option to the package to not write the external file.

I know I can set up a boolean and test for it everywhere in the package the writes take place. But it would be nice to just set the openout command at the beginning to write to /dev/null or its equivalent.

Is that possible? I need to keep this package supported on Windows, Mac, and Unix.

-

The writing is probably done by \immediate\write\STREAM{...}; I usually define a macro to stand for \immediate\write so its meaning can be changed at will

...
\newif\iftim@write
\DeclareOption{nowrite}{\tim@writefalse}
\DeclareOption{write}{\tim@writetrue}
...
\ExecuteOptions{...,nowrite}% or write, if you prefer
\ProcessOptions\relax
...

\iftim@write
\def\tim@write{\immediate\write}
\else
\let\tim@write\@gobbletwo
\fi


This code is for the case where your writing operations are done or not via a package option.

If the boolean is true, \tim@write\STREAM{...} would be expanded to \immediate\write\STREAM{...}; if the boolean is false, the same tokens would become \@gobbletwo\STREAM{...}, so \STREAM and {...} will vanish.

-
That is an elegant solution @egreg. I love its simplicity! thanks. –  Tim A Nov 12 '11 at 22:01

The command \nofiles switches off all file writing LaTeX

-
It switches off the writing of files that use \protected@write. –  egreg Nov 12 '11 at 20:19
And also disables creation of index and glossary. –  Andrey Vihrov Nov 12 '11 at 20:24
@andrey-virhov yes, this is the intended behavior –  Boris Nov 12 '11 at 20:52