[Tex/LaTex] What could cause pdflatex/lualatex to halt compilation and freeze

luatexmiktexpdftexwindows

I am trying to run pdflatex or lualatex from ASP.NET web application using impersonation. The standard output and standard error streams are being redirected and I am saving their contents to the log files.

The problem is that either pdflatex or lualatex stop after creating a zero-size chart.log file and do not complete compilation. I can only kill them from task manager.

This is what ends up in the stdout log:

This is LuaTeX, Version beta-0.76.0-2013062820 (rev 4627) 
 \write18 enabled.
(D:/Project1/Latex/chart.tex

The last line is showing the file name and that is it.

However when I run the same command line, but without using impersonation and provide domain, user name and password to the Process class instead, it runs fine, producing a PDF. Impersonation is imposed on me, unfortunately.

In order to see whether this has to do with my code, or with pdflatex/lualatex, I tried to run a simple command line program that only outputs some text to stdout, and it ran fine. Then I tried running 7zip to compress chart.tex instead and it produced chart.7z file fine as well. It sounds like the root cause is somewhere in pdflatex or lualatex programs unless I am missing something.

This is how the programs are being invoked:

    Dim p As Process = New Process()

    Try
        p.StartInfo.FileName = ConfigurationManager.AppSettings("PDFLaTeXPath")
        p.StartInfo.WorkingDirectory = "D:\Project1\Latex"
        p.StartInfo.Arguments = " --shell-escape -interaction=nonstopmode D:\Project1\Latex\chart.tex 1>nul 2>nul") ' Tried with and w/o redirecting
        p.StartInfo.UseShellExecute = False
        p.StartInfo.RedirectStandardOutput = True
        p.StartInfo.RedirectStandardError = True

        ImpersonatingContextWrapper.impersonateValidUser( _
            ConfigurationManager.AppSettings("RunAsUser"), _
            ConfigurationManager.AppSettings("RunAsDomain"), _
            ConfigurationManager.AppSettings("RunAsPassword") _
        )

        p.Start()

        Dim output As String = p.StandardOutput.ReadToEnd()
        If Not String.IsNullOrEmpty(output) Then
            My.Computer.FileSystem.WriteAllText("D:\Project1\Latex\stdout.txt", output, True)
            LogEvent(output, EventLogEntryType.Information)
        End If

        Dim errors As String = p.StandardError.ReadToEnd()
        If Not String.IsNullOrEmpty(errors) Then
            My.Computer.FileSystem.WriteAllText("D:\Project1\Latex\stderr.txt", errors, True)
            LogEvent(errors, EventLogEntryType.Warning)
        End If
        p.WaitForExit()
    Catch ex As Exception
        LogEvent("Error running PDFLaTeX compiler: " & ex.Message, EventLogEntryType.Error)
        Return False
    Finally
        ImpersonatingContextWrapper.undoImpersonation()
    End Try

Edit:

Thanks to Sean's comment, it became clear that something in the TEX file was causing a hang-up, as when I gave it a file

\documentclass{letter}
\begin{document}
abc
\end{document}

it produced the result fine. However when I ran a file below, it hung up:

\documentclass[border=10pt]{standalone}
\begin{document}
abc
\end{document}

So standalone class, which I needed to be able to produce very large documents, printed on multiple pages, is one of the root causes. Further experimenting, I found that loading any package causes a hang up. Is MikTex trying to download packages again and waiting for a confirmation, even though I am running it under my own account which already downloaded the packages?

Best Answer

Sean's comment helped to find out, that MikTex's lualatex was trying to download the packages, even though the packages were already installed previously.

Going into the MikTex Settings (Admin) program and changing Ask to Yes for installing packages on the fly, then running compilation again, resolved a hangup and produced a file.