1

When running commands like:

\immediate\write18{ls} 

in the command line, I can see the output in the command line directly in the terminal, which is practical for instance to get error messages. Unfortunately, this is not written in the .log file, so for instance in TexStudio, the log just prints:

runsystem(ls)...executed. 

Which is not really helpful for debugging. Is it possible to force LaTeX to print the output of \write18 directly in the log file? Ideally, I'd like a solution as OS-independent as possible as I need to implement it for a library.

1 Answer 1

2
\documentclass{article} \ExplSyntaxOn \NewDocumentCommand{\writecommandtolog}{m} { \sys_get_shell:nnN { ls~-1 } { } \l_tmpa_tl \exp_args:NV \iow_log:n \l_tmpa_tl } \ExplSyntaxOff \writecommandtolog{ls} \stop 

The relevant part of the log is, in my experiment,

aa.tex cc.tex tolog.log tolog.tex xyz.tex 

Adorn at will.

8
  • Thanks, but the main issue with this is that I cannot use quotes inside the command while I do use quotes… "Note that quote characters (") cannot be used inside the shell command" :-\ Commented Dec 13, 2023 at 18:38
  • @tobiasBora I'm not sure what the problem is: you cannot use quotes in \write18 to begin with. Commented Dec 13, 2023 at 18:45
  • What do you mean? If I create a file my file.txt, then \immediate\write18{cat "my file.txt"} will work but not \immediate\write18{cat my file.txt}. I am actually using quotes here, and got no error so far: github.com/leo-colisson/robust-externalize/blob/… Commented Dec 13, 2023 at 18:51
  • On the other hand, with your example I get an error ! LaTeX Error: Quotes in shell command 'cat "my file.txt"'. Commented Dec 13, 2023 at 18:53
  • 1
    @JosephWright Well, on Linux you also need quotes to deal with file names no? So what is the "good", cross-platform way of using \sys_get_shell with file names that might contain spaces? Commented Dec 13, 2023 at 19:07

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.