如何在 Perl 脚本中收集外部命令的输出?
我有一个名为 TET.EXE 的工具,它是 PDFlib 系列的产品,它用于提取特定文本的坐标。 使用 Perl 脚本中的这些坐标,我们可以提取所需的文本。 这是一个运行 .EXE 然后将坐标提供给 Perl 的手动过程,因此有人可以建议我让整个过程不受影响。
我的意思是 Perl 脚本本身应该运行 .EXE 并获取所需的坐标并提取文本。 在 Linux 中使用哪些命令来运行这个 perl 脚本? 请,我需要您对以下方面的建议。
提前致谢。
I have a a tool named TET.EXE, product of the PDFlib family, it is used to extract the co-ordinates of a particular text. Using those coordinates in the Perl script we can extract the required text. This is a manual process to run the .EXE and then give the co-ordinates to Perl, so could any one suggest me to make this entire process hands off.
What I mean is Perl script itself should run the .EXE and get the coordinates required and extract the text. What are the commands to be used in linux to run this perl script?
Please, I need your suggestions for the following.
Thanks in advance.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
如果我理解正确,您希望 perl 启动可执行文件并对打印到 stdout 的文本执行某些操作...在这种情况下,有几个选项:
使用反引号:
这会将 TED.EXE 命令的输出放入变量 $output 中,并且很可能足以满足您的需要。
使用 IPC::Open3
:运行您的命令并将 $wtr、$rdr 和 $err 关联到标准输入、输出和错误流。
还有其他方法可以完成您想要的操作(Expect.pm ,Run3 等),但是我相信上面提到的应该足够了。
If i understand correctly, you want perl to launch an executable and do something with the text printed to stdout.... in that case there are a few options:
Using backticks:
This puts the output of the TED.EXE command in the variable $output, and is most likely sufficient for what you need.
using IPC::Open3:
This runs your command and associates $wtr, $rdr and $err to the standard input, output and error streams.
There are other ways to do what you want (Expect.pm, Run3, etc), but i believe the above mentioned should be sufficient.
Perl 提供了许多运行外部程序并收集其输出的方法。 根据查看 tet.exe 我想说你最好的选择是使用 open函数并使用正则表达式循环输出以查找坐标:
Perl provides many methods for running an external program and gathering its output. Based on looking at tet.exe I would say your best bet is to use the open function and to loop over the output using a regex to find the coordinates:
如果 TET.EXE 输出到控制台,您可以使用以下命令捕获该输出。
如果您想阅读相关内容,请搜索“perl backtick”
If TET.EXE outputs to the console you can capture that output with
If you want to read about it, search for 'perl backtick'
我不明白问题,但可能是:
I don't understand question but may be:
您还可以考虑另一种方法:使用 Perl用于提取坐标的库。
You might also consider another approach: use a Perl library to extract the coordinates.
perlipc 文档展示了从 Perl 与外部进程交互的多种方法。
许多人告诉您使用反引号,但您也可以查看 IPC::System:: Simple 通过处理操作系统特定的怪癖,提供了更强大的方法来完成同样的事情。
The perlipc documentation shows many ways to interact with external processes from Perl.
Many people tell you to use backticks, but you might also check out IPC::System::Simple which provides more robust ways of doing the same thing by handling operating system specific quirks.