Question

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 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.

Was it helpful?

Solution

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:

my $output = `TED.EXE`;

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:

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

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.

OTHER TIPS

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:

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;

If TET.EXE outputs to the console you can capture that output with

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

If you want to read about it, search for 'perl backtick'

I don't understand question but may be:

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

You might also consider another approach: use a Perl library to extract the coordinates.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top