How can I get output from an external command in a Perl script?

I have a tool called TET.EXE, a product of the PDFlib family, it is used to extract the coordinates of a specific text. Using these coordinates in a Perl script, we can extract the required text. This is a manual process to run .EXE, and then give Perl coordinates, so anyone can suggest me to make the whole process without problems.

I mean, the Perl script itself should run .EXE and get the necessary coordinates and extract the text. What are the commands that will be used in linux to run this perl script? Please, I need your suggestions for the next. Thanks in advance.

+3
source share
6 answers

, , Perl - , stdout.... :

backticks:

my $output = `TED.EXE`;

TED.EXE $output , , , .

IPC:: Open3:

use IPC::Open3;
my($wtr, $rdr, $err);
my $pid = open3($wtr, $rdr, $err,
                'some cmd and args', 'optarg', ...);

$wtr, $rdr $err , .

, (Expect.pm, Run3 ..), , .

+10

Perl . tet.exe, , open :

open my $pdftext, "-|", "/path/to/tet.exe", "--text", $pdffile
    or die "could not open $pdffile using tet.exe: $!";

my ($x, $y);
while (my $line = <$pdftext>) {
    last if ($x, $y) = $line =~ /regex that matches the coords/;
}
die "file did not contain coordinates" unless defined $x;
+6

TET.EXE ,

my $tetOutput = `tet.exe /myoptions`;

, "perl backtick"

+2

, :

my $result = qx{TET.EXE some.pdf some params};
+2
+1

perlipc Perl.

Many people tell you to use backlinks, but you can also check out IPC :: System :: Simple , which provides more reliable ways of doing the same, handling specifics of the operating system.

0
source

Source: https://habr.com/ru/post/1706451/


All Articles