windowsiolatexpdflatexmiktex

MiKTeX, LaTeX: Error with \newwrite output file and writing with \write -- Windows API error 2: The system cannot find the file specified


Using TeXworks v0.6.5 (MiKTeX 20.7) on Windows 10 Home, I am trying to write a line to a text file.

When typesetting this code

\documentclass{article}

\newwrite\justafile

\begin{document}

% Write to text file:

\immediate\openout\justafile=exam.txt

\immediate\write\justafile{Chosen questions: bla, bla and bla.}

\immediate\closeout\justafile

\end{document}

the console outputs the following message (last 5 lines of the compilation log):

No pages of output.
Transcript written on example.log.

Sorry, but "MiKTeX Compiler Driver" did not succeed.

The log file hopefully contains the information to get MiKTeX going again:

  C:\Users\Miriam Briskman\AppData\Local\MiKTeX\2.9\miktex\log\texify.log

The log file carries the following error messages:

2020-09-06 19:47:38,817-0400 INFO  texify - this process (4764) started by 'miktex-texworks' with   command line: "C:\Users\Miriam Briskman\AppData\Local\Programs\MiKTeX 2.9\miktex\bin\x64\texify.exe" --pdf --synctex=1 --clean example.tex
2020-09-06 19:47:38,880-0400 INFO  texify.core - start process: pdflatex --synctex=1 "C:/Users/Miriam Briskman/OneDrive/Desktop/Brooklyn College/Fall 2020/CISC 1050/Tests/Test Pool/New folder\example.tex"
2020-09-06 19:47:39,249-0400 INFO  texify.core - start process: pdflatex --synctex=1 "C:/Users/Miriam Briskman/OneDrive/Desktop/Brooklyn College/Fall 2020/CISC 1050/Tests/Test Pool/New folder\example.tex"
2020-09-06 19:47:39,587-0400 ERROR texify.core - The system cannot find the file specified.

2020-09-06 19:47:39,587-0400 ERROR texify.core - Function: CopyFileW
2020-09-06 19:47:39,587-0400 ERROR texify.core - Result: 2
2020-09-06 19:47:39,587-0400 ERROR texify.core - Data: existing="C:/Users/MIRIAM~1/AppData/Local/Temp/mik68959/_src\example.pdf", path="C:/Users/Miriam Briskman/OneDrive/Desktop/Brooklyn College/Fall 2020/CISC 1050/Tests/Test Pool/New folder\example.pdf"
2020-09-06 19:47:39,587-0400 ERROR texify.core - Source: Libraries\MiKTeX\Core\File\win\winFile.cpp:383
2020-09-06 19:47:39,592-0400 FATAL texify - Windows API error 2: The system cannot find the file specified.

2020-09-06 19:47:39,592-0400 FATAL texify - Info: existing="C:/Users/MIRIAM~1/AppData/Local/Temp/mik68959/_src\example.pdf", path="C:/Users/Miriam Briskman/OneDrive/Desktop/Brooklyn College/Fall 2020/CISC 1050/Tests/Test Pool/New folder\example.pdf"
2020-09-06 19:47:39,592-0400 FATAL texify - Source: Libraries\MiKTeX\Core\File\win\winFile.cpp
2020-09-06 19:47:39,592-0400 FATAL texify - Line: 383

Below is a link to a screenshot of the TeXworks console with the code:

TeXworks console with the problematic code

I installed all the recent updates using the MiKTeX console, but this did not solve the issue.

What is the source of the error, and how should I fix it?


Solution

  • Stay way from texify whenever possible.

    Instead I suggest to either