3

I have a shell script to generate two types of reports. Each report is generated by executing a Sweave script and then compiling a PDF out of the resulting tex file.

eval "R CMD Sweave Weekly.Rnw"
eval "pdflatex Weekly.tex"
eval "R CMD Sweave Daily.Rnw"
eval "pdflatex Daily.tex"

For instance, if there is an error when executing 'R CMD Sweave Weekly.Rnw', it exits but still generates a tex file (which I have checked cannot be stopped) and this tex file would not compile correctly in pdflatex i.e. 'pdflatex Weekly.tex' command would hang and the shell script will not move to the next 'R CMD Sweave Daily.Rnw'.

Now, my question: If I know that a certain shell command should not take more 30 secs, is there a way to induce a timed exit from that command (assuming it hung) after say a couple minutes (or some arbitrary time lapse)? Alternatively, is there a way to force shutdown a latex engine after it encounters errors when compiling a tex file?

bad_coder
  • 11,289
  • 20
  • 44
  • 72
Arjun
  • 157
  • 1
  • 7
  • 3
    Why are you using `eval`? As the bash faq says *"eval is a misspelling of evil, if the answer is eval, you are asking the wrong question"* – SiegeX Jan 02 '12 at 07:14
  • There are contexts where `eval` is appropriate; it is very far from clear that this is one of them. – Jonathan Leffler Jan 02 '12 at 07:26
  • 1
    possible duplicate of [Command line command to auto-kill a command after a certain amount of time](http://stackoverflow.com/questions/601543/command-line-command-to-auto-kill-a-command-after-a-certain-amount-of-time) – Jonathan Leffler Jan 02 '12 at 07:29

3 Answers3

3

Use pdflatex -halt-on-error to stop pdflatex from asking questions.

Simon Urbanek
  • 13,842
  • 45
  • 45
  • 1
    You mean `pdflatex -interaction=batchmode`. `pdflatex -halt-on-error` lets pdflatex exit on the first error. – Martin Schröder Jan 02 '12 at 20:12
  • Yes, but that was the point ... why would you bother generating more errors if you know the file is corrupt? Batch mode has other implications, so it may or may not be what you want. – Simon Urbanek Jan 02 '12 at 20:33
  • 1
    `pdflatex -interaction=nonstopmode` seems to work best, since it helps jump over all user interactions, which typically are error related interactions. – Arjun Jan 02 '12 at 22:35
2

See R.utils::evalWithTimeout or setTimeLimit - these can interrupt commands, shell or otherwise, I believe, when a timeout is reached and as long as the command can be interrupted by the user.

Iterator
  • 20,250
  • 12
  • 75
  • 111
0

Or, if that pdflatex is being called from R CMD check, and you don't know how to pass arguments to pdflatex, and you are using Windows, then an alternative is :

  • Start->Programs->MikTex 2.9->Maintenance (Admin)->Settings (Admin)

and then :

  • Click Refresh FNDB
  • Click Update Formats
  • Change Install missing packages on-the-fly to No

This should fix the R CMD check appears to hang error on "checking re-building of vignette PDFs ..." or "checking PDF version of manual ..." problem.

Matt Dowle
  • 58,872
  • 22
  • 166
  • 224