I run a sequence of latex commands from a bash script. Since the latex output polutes the scripts own output I would like to suppress it. But sending the output to /dev/null will make the latex process inaccesible for the user. Hence it could be killed only manually in case there is a compilation error. How can I control latex from within the script. I.e. suppress the output and exit the process in case of error.
Asked
Active
Viewed 1,325 times
3
1 Answers
4
As asked above by egreg, I'm turning my comments into answer.
I'm using this command om my script and I'm satisfied with it.
pdflatex -halt-on-error file.tex 1> /dev/null
[[ $? -eq 1 ]] && echo "msg in case of erros" && exit
In case of errors, the msg will appear. Otherwise, the output will be send to null.
Now, you can try to improve with a command to search for your file before running pdflatex.
Sigur
- 37,330
-
1Not the best
bashI've seen in my life...1>is funny, so is the&& exit. Also,[[ $? -eq 1 ]]is not the best idea, just in casepdflatexreturns another (non-zero) code. How about(( $? )) && echo "msg in case of errors"instead ? – gniourf_gniourf Nov 04 '12 at 00:00 -
I don't know. For me, it works! But if there are better solutions, thanks for helping. – Sigur Nov 04 '12 at 00:58
pdflatex --interaction=batchmode? – egreg Jul 16 '12 at 15:27pdflatex -halt-on-error file.tex 1> /dev/null [[ $? -eq 1 ]] && echo "msg in case of erros" && exitWith this, in case of errors, the msg will appear. Otherwise, the output will be send to null.
– Sigur Jul 16 '12 at 16:45file.texdoesn't exist (which is one possible error). – Bruno Le Floch Jul 17 '12 at 16:08$?has the result of any command. Usually it could be zero or not. You can test it. – Sigur Jul 17 '12 at 19:58latex --interaction=nonstopmode "file.tex" &>/dev/null. Then I check the exit state in $?. The halt-on-error is not appropriate for me as I don't want it to stop for errors in individual files (if there are nasty errors in many files it can take me ages to confirm all of them). Whats the difference to--interaction=batchmode? – highsciguy Jul 18 '12 at 08:56yes? E.g.,yes '^D' | pdflatex "$file"(where ^D is input with Ctrl+V+Ctrl+D). With this, if pdflatex is waiting for some input, it receives a nice EOF, so user doesn't need to kill it.-halt-on-errorfails if file doesn't exists or if it never finishes... – gniourf_gniourf Nov 03 '12 at 23:58