I create in my folder a file "blub.temp" and then tried out the following

%correct small bug in shellesc:
\protected\def\ShellEscape{\immediate\write18 }

\ShellEscape{kpsewhich article.cls    >> blub.temp}

\immediate\write18{kpsewhich book.cls >> blub.temp}


When I compile this (pdflatex on miktex, texlive 2015, texlive 2016) without shell-escape I see messages like this in the log-file

 runsystem(kpsewhich book.cls >> blub.temp)...executed safely (allowed).

But blub.temp has no content.

When I compile with --shell-escape I see messages like

 runsystem(kpsewhich book.cls >> blub.temp)...executed.

and blub.temp contains the both pathes.

How can it be that the command is executed but does nothing when --shell-escape is not used? Can one correct this?


As confirmed on the texlive list, redirections (>, >>) don't work in restricted mode. So the question is if there is any other way to catch the output of kpsewhich (without pipes or --shell-escape) ...

  • kpsewhich is in the list of programs allowed in the restricted shell; but in this case it is not allowed to write files, as far as I can see. I guess that Karl Berry is the one who can answer this; probably output redirection is not allowed in the restricted shell.
    – egreg
    Apr 29, 2016 at 9:24
  • @egreg: I will ask. I see some arguments why such redirections are disallowed, but I now wonder how to catch the output of kpsewhich ... Apr 29, 2016 at 9:40
  • tex.stackexchange.com/a/179748/4427, but probably you already knew it
    – egreg
    Apr 29, 2016 at 9:47
  • @egreg: Well it was my question ;-). Also I commented Heikos answer and the comment still stands: problematic in miktex. Apr 29, 2016 at 10:39
  • Where is shellesc to be found? At least for me, CTAN search doesn't find it. This is weird because it is clearly in TeX Live. Is there a way to find these things on CTAN? I told it to search everything, including file names.
    – cfr
    Apr 29, 2016 at 15:15

1 Answer 1


What about Lua?

    local fp = io.popen("kpsewhich article.cls")
    local fh = io.open("blub.temp", "a")
    while true do
       local line = fp:read()
       if line == nil then
       fh:write(line, "\noexpand\n")
  • Yes, this works but I can't currently remember if lua was an option ;-). May 23, 2016 at 14:55

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.