# How do you detect restricted write18 support

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 `\write18`is allowed to use and thus want to check, if it's restricted. How do you do this properly?

• 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. Dec 30 '12 at 15:13

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

``````\usepackage{pdftexcmds}

\makeatletter
\ifcase\pdf@shellescape
\message{No shell escape}\or
\message{Unrestricted shell escape}\or
\message{Restricted shell escape}\fi
\makeatother
``````

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

``````\ifnum\pdf@shellescape=\tw@
\begingroup
\everyeof{\noexpand}
\typeout{%
***************^^J%
* Restricted shell-escape is available; the allowed programs are^^J%
* \@@input|"kpsewhich --var-value shell_escape_commands" ^^J%
***************}
\endgroup
``````

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