I know about \ifeof18 and \pdfshellescape to detect, if \write18 is enabled, but both only tell me, if it's enabled at all. I need to use a program which isn't in the list of commands restricted \write18is allowed to use and thus want to check, if it's restricted. How do you do this properly?

  • 3
    If only the restricted shell is enabled, then the integer parameter \pdfshellescape equals 2. In XeTeX it's \shellescape and in LuaTeX it's missing. With the pdftexcmds package you can test the status of the shell independently from the engine.
    – egreg
    Dec 30 '12 at 15:13

The best method for testing the shell-escape is use the pdftexcmds package:


  \message{No shell escape}\or
  \message{Unrestricted shell escape}\or
  \message{Restricted shell escape}\fi

Of course you can put any code you want. Note that on older TeX distributions this can give wrong results when LuaTeX (version number less than 0.68) is used.

The package uses the integer \pdfshellescape if pdftex is used, \shellescape with xetex and emulates the register with a Lua function with LuaTeX.

The integer's value is

0, if the shell escape is disabled (a call like pdflatex -no-shell-escape)

1, if the shell escape is unrestricted (a call like pdflatex -shell-escape)

2, if the shell escape is restricted (a simple call pdflatex)

(the above holds under normal setting of the variable shell_escape in texmf.cnf to the value p).

With pdflatex you can list the allowed programs in restricted shell escape with

    * Restricted shell-escape is available; the allowed programs are^^J%
    * \@@input|"kpsewhich --var-value shell_escape_commands" ^^J%

but unfortunately this can't be done with xelatex and lualatex (for the latter some Lua function might help). The output is

* Restricted shell-escape is available; the allowed programs are
* bibtex,bibtex8,kpsewhich,makeindex,mpost,repstopdf, 
  • This works great, I just read the documentation of pdftexcmds. There seems to be no way to get the list of commands that are allowed though. Is this also possible?
    – Max
    Dec 30 '12 at 15:46

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.