1

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?

  • 3
    It would also be good to know what kinds of files it hangs up on. Do you have a few examples? – Sean Allred Jun 26 '14 at 22:38
  • I suspect a problem with permissions. – Martin Schröder Jun 27 '14 at 11:43
  • In a similar case I called a .bat file instead which contained lots of diagnostics before calling lualatex. If the directory, parameters, environment variables, etc. are all identical lualatex should behave also in the same way as called from the command line. – Alexander Jun 27 '14 at 12:47
  • 1
    @SeanAllred Your theory is correct, please see the edit re standalone class. – ajeh Jun 27 '14 at 13:14
  • Yes! It's downloading packages according to the resource monitor. I switched off a confirmation for package installation in Settings (admin) and it finally worked, even though initially it looked like another hangup... Weird, why would it have to d/l the packages all over again under impersonation? – ajeh Jun 27 '14 at 13:25
1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.