6

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

\documentclass{article} \usepackage[T1]{fontenc} \usepackage{shellesc} %correct small bug in shellesc: \protected\def\ShellEscape{\immediate\write18 } \begin{document} \ShellEscape{kpsewhich article.cls >> blub.temp} \immediate\write18{kpsewhich book.cls >> blub.temp} \end{document} 

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?

Edit

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) ...

6
  • 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. Commented 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 ... Commented Apr 29, 2016 at 9:40
  • tex.stackexchange.com/a/179748/4427, but probably you already knew it Commented 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. Commented 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. Commented Apr 29, 2016 at 15:15

1 Answer 1

1

What about Lua?

\documentclass{article} \begin{document} \directlua{ 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 break end fh:write(line, "\noexpand\n") end fh:close() fp:close() } \end{document} 
1
  • Yes, this works but I can't currently remember if lua was an option ;-). Commented May 23, 2016 at 14:55

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.