# Shell-escape with LaTeX 3

What is the LaTeX 3 equivalent to \write18 if there is one? I want to call lilypond from within my TeX document.

-
Do you mean \tex_write:D? But :D means "Do not use it". –  Marco Daniel Sep 14 '13 at 15:33
\int_const:Nn \c_eighteen and then \iow_now:Nn \c_eighteen{...} is equivalent to \immediate\write18{\unexpanded{...}}; but probably one should define some new function based on this. –  egreg Sep 14 '13 at 16:57

There is no function in LaTeX3, at the moment, dealing with \write18; it can be obtained by

\RequirePackage{expl3,pdftexcmds}
\ExplSyntaxOn
\int_const:Nn \c_tobi_eighteen_int { 18 }
\int_const:Nn \c_tobi_shell_escape_int { \int_eval:n { \use:c { pdf@shellescape } } }
\cs_new_protected:Npn \tobi_system_exec_now:n #1
{
\int_compare:nT { \c_tobi_shell_escape_int > 0 }
{ \iow_now:Nn \c_tobi_eighteen_int { #1 } }
}
\cs_new_protected:Npn \tobi_system_exec_shipout:n #1
{
\int_compare:nT { \c_tobi_shell_escape_int > 0 }
{  \iow_shipout:Nn \c_tobi_eighteen_int { #1 } }
}
\cs_generate_variant:Nn \tobi_system_exec_now:n { x }
\cs_generate_variant:Nn \tobi_system_exec_shipout:n { x }

%% Examples
\tobi_system_exec_now:n { ls }
\tl_set:Nn \l_tmpa_tl { ls }
\tobi_system_exec_now:x { \l_tmpa_tl }


You probably would want to add messages telling that things went wrong when shell escape is disabled; or just remove the \int_compare:nT thing.

I used the tobi prefix because using \system is probably a bad idea (I don't want to get slapped by Joseph on chat, you know).

-
Indeed, a good question here is what does and doesn't make sense interface-wise for this. As the team have not needed \write18 we've not worried out it. Notable of course is that catcodes might be an issue. –  Joseph Wright Sep 14 '13 at 19:55
@JosephWright Catcodes can surely be an issue; but I guess the function will be called with its argument coming from "user space". Otherwise, spaces must be ~, as usual. Setting up a good diagnostic system might be tricky, because of restricted shell. –  egreg Sep 14 '13 at 20:01
@JosephWright: don't you guys dare including a \write18 equivalent function in LaTeX3, I already printed interface3.pdf today! :) –  Paulo Cereda Sep 14 '13 at 20:05
Seems to work fine. Thank you! –  Tobi Sep 15 '13 at 8:18