G'day Takamoto,
[I created a quick test.pdf, with just the text "Test for PM 11148715", for the tests below. I don't have p2t, but I do have pdftotext, which appears to have the same functionality and accepts the same options.]
You appear to have got bogged down in absolute vs. relative paths and eval code.
If your p2t is in a directory listed in $PATH, you don't technically need a path at all; however, using an absolute path avoids tainting.
If all you want to do is print the PDF text, you can use system() or backticks like one of these:
$ perl -e 'system "pdftotext -nodiag -layout -enc UTF-8 test.pdf -"' Test for PM 11148715 $ perl -e 'print `pdftotext -nodiag -layout -enc UTF-8 test.pdf -`' Test for PM 11148715
If you want something a little more robust, that avoids the overhead of using the shell, consider capturex() from IPC::System::Simple. Here's an example (p2t_capturex.pl):
#!/usr/bin/env perl use strict; use warnings; use IPC::System::Simple 'capturex'; my $p2t_exe = 'C:/cygwin64/bin/pdftotext.exe'; my $pdf_doc = 'test.pdf'; print capturex( $p2t_exe => qw{-nodiag -layout -enc UTF-8}, $pdf_doc, '-' );
You get the same output as before:
$ ./p2t_capturex.pl Test for PM 11148715
In case you were wondering, that's the same pdftotext program throughout. Note the identical inode numbers:
$ ls -i1 `which pdftotext` C:/cygwin64/bin/pdftotext.exe 844424931368301 /usr/bin/pdftotext 844424931368301 C:/cygwin64/bin/pdftotext.exe
— Ken
In reply to Re: use of Backticks to catch console output
by kcott
in thread use of Backticks to catch console output
by Takamoto
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |