tags:

views:

53

answers:

4

How can you set a string to be used instead of standard input? For example, when running the latex command in Unix it will always find some trivial errors, to skip through all errors you have to enter "r" into the command line (I now know that with latex specifically you can use -interactionmode nonstopmode, but is there a more general solution to do this?) Is there anyway to specify that this should be done automatically? I tried redirecting standard input to read from a file containing "r\n", but this didn't work. How can I achieve this?

A: 

From the man page:

-interaction mode

Sets the interaction mode. The mode can be either batchmode, nonstopmode, scrollmode, and errorstopmode. The meaning of these modes is the same as that of the corresponding \commands.

Looks like -interaction nonstopmode might help you.

casablanca
That does answer my question of how to do it specifically for latex, but not quite my other part about how to automate input
Tom
In general, what you did (redirect standard input) should work, but it will fail if the program reads directly from the console instead of standard input, in which case there is no easy solution. But I doubt LaTeX falls into this category - maybe you overlooked something simple.
casablanca
+1  A: 
latex --interaction=MODE

where MODE is one of:

  • errorstopmode: stop at every error and ask for input
  • scrollmode: scroll over non-fatal errors, but stop at fatal errors (such as "file not found")
  • nonstopmode: scroll over non-fatal errors, abort at fatal errors
  • batchmode: like nonstopmode, but don't show messaes at the terminal

For interactive use, errorstopmode (the default) is fine, for non-interactive use, nonstopmode and batchmode are better.

But beware, there are no trivial errors: all errors must be fixed, and all warnings should be fixed if possible.

Redirecting stdin works without problems here:

/tmp $ tex '\undefined\end' <<< r
This is TeX, Version 3.1415926 (TeX Live 2010)
! Undefined control sequence.
<*> \undefined
              \end
? OK, entering \nonstopmode...
(see the transcript file for additional information)
No pages of output.
Transcript written on texput.log.
Philipp
+4  A: 

Not all applications that need input can be satisfied with their stdin redirected.

This is because the app can call the isatty C function (if written in C, or some equivalent call for other languages) to determine if the input come from a tty or not.

In such situation, there is a valuable tool to use, and this is expect.

enzotib
+2  A: 

You've got two plausible answers detailing the way to handle Latex specifically. One comment indicates that you need a more general answer.

Most usually, the tool recommended for the general solution is 'expect'. It arranges for the command to have a pseudo-tty connected for input and output, and the command interacts with the pseudo-tty just as it would your real terminal. You tell 'expect' to send certain strings and expect certain other strings, with conditional code and regular expressions to help you do so.

Expect is built using Tcl/Tk. There are alternative implementations for other languages; Perl has an Expect module, for example.

Jonathan Leffler