summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/doc/generic/FAQ-en/html/FAQ-spawnprog.html
blob: 0d0f1e1ae092754cea73c642f8e6daebcb79a454 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
<head>
<title>UK TeX FAQ -- question label spawnprog</title>
</head><body>
<h3>Spawning programs from (La)TeX: <code>\</code><code>write18</code></h3>
<p/>The TeX <a href="FAQ-write.html"><code>\</code><code>write</code> primitive instruction</a> is used
to write to different file &#8216;streams&#8217;; TeX refers to each open file by
a number, not by a file name (although most of the time we hide this).
Originally, TeX would write to a file connected to a stream
numbered 0&#8211;15.  More recently, a special &#8220;stream 18&#8221; has been
implemented: it is not writing to a file, but rather tells TeX to ask
the operating system to do something.  To run a command, we put it as
the argument to <code>\</code><code>write18</code>.  So to run the <i>epstopdf</i>
program on a file with name stored as <code>\</code><code>epsfilename</code>, we would
write:
<blockquote>
<pre>
\write18{epstopf \epsfilename}
</pre>
</blockquote><p>
When using something like the <i>epstopdf</i> package, the &#8216;stream&#8217;
write operation is hidden away and you don&#8217;t need to worry about the
exact way it&#8217;s done.
<p/>However, there is a security issue. If you download some (La)TeX code from
the Internet, can you be sure that there is not some command in it
(perhaps in a hidden way) to do stuff that might be harmful to your
PC (let&#8217;s say: delete everything on the hard disk!)?  In the
face of this problem, both MiKTeX and TeX Live have, for some
time, disabled <code>\</code><code>write18</code> by default.  To turn the facility on,
both distributions support an additional argument when starting TeX
from the command shell:
<blockquote>
<pre>
(pdf)(la)tex --shell-escape &#60;file&#62;
</pre>
</blockquote><p>
The problem with this is that many people use (La)TeX via a graphical
editor, so to use <code>\</code><code>write18</code> for a file the editor&#8217;s settings must
be changed.  Of course, the settings need restoring after the file is
processed: you defeat the point of the original protection, that way.
<p/>The latest MiKTeX (version 2.9), and TeX Live (2010 release) get
around this by having a special &#8220;limited&#8221; version of <code>\</code><code>write18</code>
enabled &#8216;out of the box&#8217;.  The idea is to allow only a pre-set list of
commands (for example, BibTeX, <i>epstopdf</i>, TeX itself,
and so on).  Those on the list are regarded as safe enough to allow,
whereas anything else (for example deleting files) still needs to be
authorised by the user. This seems to be a good balance: most people
most of the time will not need to worry about <code>\</code><code>write18</code> at all,
but it will be available for things like <i>epstopdf</i>.
<p/>Note that the TeX system may tell you that the mechanism is in use:
<blockquote>
<pre>
This is pdfTeX, Version 3.1415926-1.40.11 (TeX Live 2010)
 restricted \write18 enabled.
</pre>
</blockquote><p>

when it starts.
<dl>
<dt><tt><i>epstopdf.sty</i></tt><dd>Distributed with Heiko Oberdiek&#8217;s packages
  <a href="http://mirror.ctan.org/macros/latex/contrib/oberdiek.zip">macros/latex/contrib/oberdiek</a> (or <a href="http://mirror.ctan.org/macros/latex/contrib/oberdiek/">browse the directory</a>); <a href="http://mirror.ctan.org/help/Catalogue/entries/oberdiek.html">catalogue entry</a>
</dl>
<p/><p>This question on the Web: <a href="http://www.tex.ac.uk/cgi-bin/texfaq2html?label=spawnprog">http://www.tex.ac.uk/cgi-bin/texfaq2html?label=spawnprog</a>
</body>