3

When compiling a single ConTeXt file, I can see if the compile was successful by looking at the final lines and by watching it compile.

I have a batch file that compiles thousands of ConTeXt text files. Compilation can take greater than 24 hours. A simple example of this is:

#!/bin/bash

for file in 1 2 3 4 5 6
do
    context $file\.tex
done

The problem is, it is encounters an error with 3.tex, I have no way of really checking, unless I spend the whole 24 hours watching the files compile. When there is an error, ConTeXt quits, but the BASH script continues, and continues to run compile. Often a PDF which should be 1,000 pages is instead only 1 page. Othertimes, the file should be 835 pages, but it broke at 563 pages, but created a PDF. So I don't know which PDFs are bad and which compiled successfully.

How can I output a kind of long which tells me which of the files had errors during the compiling?

  • This is off-topic for this site. Provided context is well-behaved, it will return a numerical result. Typically, 1 for failure` or some other number for a specific error and 0 for success. So test if the return is 0. If not, it isn't successful. Then write yourself an error message or log file somewhere with the current file name. – cfr Apr 6 '17 at 2:15
  • The man page is sorely lacking on this point. Any manual page should provide this much information. – cfr Apr 6 '17 at 2:16
  • It works for pdftex, though the manual page is equally unhelpful. However, I don't know enough context to produce a working document to compare the outputs. But I'd assume that it will be equally well behaved. Hence, just treat it as any other execution and use the usual Bash process management facilities. – cfr Apr 6 '17 at 2:20
  • Is any of the answers acceptable for you? If not, how can they be improved? – Henri Menke Apr 17 '17 at 9:39
3

This records the number and names of files which fail to compile. This information is date and time-stamped, so that previous records can be retained without ambiguity.

#!/bin/bash -
# set PATH explicitly here
# export PATH=/usr/local/bin:/usr/bin
logfile="${HOME}/context.log"
date >> $logfile
printf %b "\n" >> $logfile
failures=0

for file in 1 2 3 4 5 6; do
    context --nonstopmode "${file}.tex"
    if [ $? != 0 ]
    then
      printf %b "${file}.tex\n" >> $logfile
      ((failures+))
    fi
done

printf %b "${failures} failures.\n\n" >> $logfile

exit $failures
5

Use set -e. This will terminate the bash script as soon as one of the commands called returns a non-zero exit status. Also use --nonstopmode (or --batchmode if you don't want console output), otherwise ConTeXt will wait for user input on error.

#!/bin/bash

set -e;

for file in 1 2 3 4 5 6; do
    context --nonstopmode "${file}.tex"
done

Another possibility is to examine the exit status which is stored in $?.

#!/bin/bash

# Clear error log
echo "" > error.log

for file in 1 2 3 4 5 6; do
    context --nonstopmode "${file}.tex";
    if [ $? -ne 0 ]; then
        echo "Error in file ${file}" >> error.log
    fi
done

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.