2

Casually, I run into trouble while using the filecontents package: LaTeX complains that the data file created by the filecontents environment is not writeable:

LaTeX Warning: Overwriting file `./data.tex'.
! I can't write on file `data.tex'.
<to be read again>
                   \relax
l.6 \begin{filecontents*}{data.tex}

Just pressing return helps. I suspect that MS Windows uses some file access control mechanism which sometimes does not "unlock" the file in time before another LaTeX compilation tries to "lock" and write the same file again (running on a rather fast system with SSD). Maybe my anti virus software (Symantec) creates this problem, being busy with checking the newly created file.

Is there any trick to help this mechanism from within LaTeX? Flush the file cache? Delay processing several milliseconds?

Details:

Admitted, I have a large set of document files (100+) which are processed one after another in a batch job by a single DOS script which calls LaTeX subsequently for all files. One process calls LaTeX many times in a row.

A typical LaTeX document file looks like this:

\documentclass[varwidth=469pt]{standalone}
\begin{filecontents*}{data.tex}
  \begin{tabular}{|c|l|c|}
    Data & Parameter & Hex
  \end{tabular}
\end{filecontents*}

\begin{document}
  \input{data.tex}
\end{document}

A typical DOS script looks like this (but contains many more calls to pdflatex):

D:
cd "/foo/bar/GeneratedImages"
pdflatex 27.tex
pdflatex 56.tex
pdflatex 161.tex
pdflatex 231.tex

And currently, I am reusing the same file data.tex for all documents which is the reason why this problem appears.

If there is no such fix, I would try to avoid using the filecontents package (and thus replace ltxtable by ltablex). Or include \jobname into the data file's name (file spam).

3
  • Not sure I fully understand. You have a bunch of LaTex compilations, all running simultaneously, and all writing and accessing the same files. That will surely cause inevitable and unsolve-able problems. Can you not fix your batch script so that one run is initiated after the last has ended. Are all your other temporary files in the same folder as well?? It might be helpful to show your script as well. Commented Aug 12, 2015 at 11:38
  • @Aubrey Blumsohn: not running simultaneously, but subsequentially, compiling one file after another. There is only one process, calling LaTeX many times. Usually this goes very well, just sometimes there appears to be such a locking problem. (Edited the original post to make this more clear).
    – Twonky
    Commented Aug 12, 2015 at 12:16
  • 1
    How do you know they are not running simultaneously? The fact that you are calling one after the next in your batch script does not mean the second will only start after the first ends. That's why you need to show the script. For example the 'call' command might let it know to return back to your script after the called script completes. Commented Aug 12, 2015 at 13:43

1 Answer 1

2

The easiest way would be to make the file name unique using \jobname:

\documentclass[varwidth=469pt]{standalone}
\begin{filecontents*}{\jobname-data.tex}
  \begin{tabular}{|c|l|c|}
    Data & Parameter & Hex
  \end{tabular}
\end{filecontents*}

\begin{document}
  \input{\jobname-data.tex}
\end{document}

with \jobname expanding to 27, 56, 161, 231, according to your example.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .