如何执行自动 Unix 输入?

发布于 2024-09-27 00:23:24 字数 221 浏览 2 评论 0原文

如何设置要使用的字符串而不是标准输入?例如,在 Unix 中运行 Latex 命令时,它总是会发现一些微不足道的错误,要跳过所有错误,您必须在命令行中输入“r”(我现在知道,对于 Latex,您可以使用 -interactionmode nonstopmode,但是有没有更通用的解决方案来做到这一点?) 无论如何指定这应该自动完成吗?我尝试重定向标准输入以从包含“r\n”的文件中读取,但这不起作用。 我怎样才能实现这个目标?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

淡淡の花香 2024-10-04 00:23:24

并非所有需要输入的应用程序都可以满足其标准输入重定向。

这是因为应用程序可以调用 isatty C 函数(如果用 C 编写,或其他语言的等效调用)来确定输入是否来自 tty。

在这种情况下,有一个很有价值的工具可以使用,这就是expect

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.

分开我的手 2024-10-04 00:23:24
latex --interaction=MODE

其中 MODE 是以下之一:

  • errorstopmode:在每个错误处停止并要求输入
  • scrollmode:滚动非致命错误,但在致命错误处停止错误(例如“找不到文件”)
  • nonstopmode:滚动非致命错误,出现致命错误时中止
  • batchmode:类似于 nonstopmode,但是不要在终端显示消息

对于交互式使用,errorstopmode(默认)就可以,对于非交互式使用,nonstopmodebatchmode更好。

但请注意,不存在微不足道的错误:必须修复所有错误,并且如果可能的话,应修复所有警告。

重定向 stdin 在这里没有问题:

/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.
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.
你的呼吸 2024-10-04 00:23:24

您有两个看似合理的答案,详细说明了具体处理 Latex 的方法。一条评论表明您需要一个更笼统的答案。

最常见的是,推荐用于通用解决方案的工具是“expect”。它安排命令连接一个伪 tty 以进行输入和输出,并且该命令与伪 tty 交互,就像与真实终端交互一样。您告诉“期望”发送某些字符串并期望某些其他字符串,并使用条件代码和正则表达式来帮助您做到这一点。

Expect 是使用 Tcl/Tk 构建的。其他语言也有替代实现;例如,Perl 有一个 Expect 模块。

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.

最佳男配角 2024-10-04 00:23:24

手册页

-交互模式

设置交互模式。该模式可以是批处理模式、不间断模式、滚动模式和错误停止模式。这些模式的含义与相应\命令的含义相同。

看起来 -interaction nonstopmode 可能对您有帮助。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文