backticks not running application (please help!)

D

Dan

Dear All,

The following lines of code work from from Terminal (OS-X), but do not
return anything when run within a CGI-script...

$foo = `/opt/local/bin/gocr`;
print $foo;

Is this a permissions issue? All I want to do is print the text
outputted by a command-line ocr program.

Any clues? Any way round it? Its running on my Apple X.4.4 PowerBook
running Apache.

Is there a better way of getting the output from an application?

Thanks,

Dan
 
X

xhoster

Dan said:
Dear All,

The following lines of code work from from Terminal (OS-X), but do not
return anything when run within a CGI-script...

$foo = `/opt/local/bin/gocr`;
print $foo;

Assuming the selected handle is still STDOUT, you could probably combine
these statements with:

system "/opt/local/bin/gocr";

(although there may be some buffering issues.)

Is this a permissions issue?

How should we know? If you want to know why system calls fail, ask Perl
or the system, not us. Check the value $? after the call, and check
wherever it is you redirect STDERR to for errors, warnings, and messages.


Xho
 
D

Dan

Sorry - i should have been clearer...

$? does not report anything at all, and error_log doesn't highlight any
error either.

I have changed the permissions of the application to ensure that anyone
can exec, it works in Terminal but not from the browser?!? Am I still
deep in the stupid UNIX hole phase that I thought I was swimming my way
out of?

Any advice strongly appreciated.

Dan
 
D

Dan

MORE INFO...

1. Sorry for not quoting your message (don't know what I was thinking)
2. Using system(), I get the error '256' in my web-browser. Any ideas?

 
D

Dan

EVEN MORE INFO...

if I use the code...

system "/opt/local/bin/gocr -i
/Library/WebServer/Documents/scans/SKMBT_C25006012712070_0005.jpg -o
/Library/WebServer/Documents/scans/test.txt";
print "$?";

then both Terminal and Apache create the text file, but Apache does not
fill it populate the file with the OCR results (Terminal does). This is
bending my brain.
 
A

Anno Siegel

Dan said:
EVEN MORE INFO...

if I use the code...

system "/opt/local/bin/gocr -i
/Library/WebServer/Documents/scans/SKMBT_C25006012712070_0005.jpg -o
/Library/WebServer/Documents/scans/test.txt";
print "$?";

then both Terminal and Apache create the text file, but Apache does not
fill it populate the file with the OCR results (Terminal does). This is
bending my brain.

Could be because it can't read the input file.

Start debugging the thing. Don't just stare at incomprehensible results,
it's your code, you can change it. Put something like this in there:

die "Can't read input" unless
-r "/Library/WebServer/Documents/scans/SKMBT_C25006012712070_0005.jpg";

Then check the error log for the message, or divert errors to the browser.
Then you'll *know* if the input file is readable for the process.

And so on...

Anno
 
D

Dan

Anno,

Thanks for getting back to me, i think i might be getting there... the
source and distination files are both readable, but i have a new error
in error_log...

ERROR pnm.c L213: read
[Wed Feb 1 12:12:52 2006] [error] [client 127.0.0.1] File does not
exist: /Library/WebServer/Documents/favicon.ico
sh: line 1: djpeg: command not found


It looks to me like the djpeg file is inaccessible to gocr - maybe a
path issue? any ideas how i might test this theory?

Thanks ever so much,

Dan

Could be because it can't read the input file.
Start debugging the thing. Don't just stare at incomprehensible results,
it's your code, you can change it. Put something like this in there:
 
A

Anno Siegel

Please place your reply after the text you are replying to. I have
re-arranged the text.
Anno,

Thanks for getting back to me, i think i might be getting there... the
source and distination files are both readable, but i have a new error
in error_log...

Two postings ago you swore there were *no* errors in error_log.
ERROR pnm.c L213: read
[Wed Feb 1 12:12:52 2006] [error] [client 127.0.0.1] File does not
exist: /Library/WebServer/Documents/favicon.ico
sh: line 1: djpeg: command not found


It looks to me like the djpeg file is inaccessible to gocr - maybe a
path issue? any ideas how i might test this theory?

The same way I showed you to test for readability of the input file.
Find the full path of djpeg, and die if it isn't executable (-x).

Anno
 
D

Dan

Could be because it can't read the input file.
Two postings ago you swore there were *no* errors in error_log.

That is true - there weren't. Then there were. No idea what changed.

Thanks for your help, i know i'm being annoying (your debugging advice
will prove invaluable I'm sure)...

Changing permissions for djpeg has got rid of part of the error
(although the script did not die when i tested it with -x), now i'm
left with...

ERROR pnm.c L213: read

I can't find pnm.c anywhere on my system (could be the problem?) - do
you have any idea what it is? All of the references I can find on the
web are to do with compiling AV apps or Gimp.

I've never had so much trouble with such a simple script!

Cheers,

Dan
 
A

Anno Siegel

Dan said:
That is true - there weren't. Then there were. No idea what changed.

Thanks for your help, i know i'm being annoying (your debugging advice
will prove invaluable I'm sure)...

Changing permissions for djpeg has got rid of part of the error
(although the script did not die when i tested it with -x), now i'm
left with...

ERROR pnm.c L213: read

I can't find pnm.c anywhere on my system (could be the problem?) - do
you have any idea what it is? All of the references I can find on the
web are to do with compiling AV apps or Gimp.

At a guess, that's probably an error message generated from the code in
pnm.c, line 213. If so, it doesn't mean the file (pnm.c) is missing or
unreadable, but it tries to read something else and fails.
I've never had so much trouble with such a simple script!

CGI is never simple.

Anno
 
X

xhoster

Dan said:
Sorry - i should have been clearer...

$? does not report anything at all, and error_log doesn't highlight any
error either.

Maybe you are not logging correctly.

I would change my command to something obviously erroneous, just to make
sure that if errors were occuring, that you would catch them.

system "zcat /dev/null"

Xho
 
B

Big and Blue

Dan said:
The following lines of code work from from Terminal (OS-X), but do not
return anything when run within a CGI-script...

$foo = `/opt/local/bin/gocr`;
print $foo;

Is this a permissions issue? All I want to do is print the text
outputted by a command-line ocr program.

Based on your later postings that program probably expects some input?
But you haven't given it any. Not unreasonable for an OCR program to
output nothing when it's been given nothing to CR.
 
L

les.peters

For situations where I need the output of a program, I tend to use
something like this:

if (! open(GOCR, " /opt/local/bin/gocr |") {
print STDERR "failed to execute gocr: $!\n";
} else {
while(<GOCR>) {
chomp;
$foo .= $_;
}
close(GOCR);
}

Optionally, you could test the -x-ness of the program/script in
question before
attempting to run it.

I am also assuming that gocr is in fact the GNU OCR program, so there
may be
a Perl module that can process the data from within your script without
invoking
the external program (increasing portability, but also increasing your
reliance on
infrequently-installed modules).
 
D

Dan

Dear All,

The author of the application has been in touch with me with the
following resolution:

Call djpeg from my script and pipe it to gocr. Problem solved, jobs a
good 'un.

Thanks for all of your help...

Dan
 
T

Tad McClellan

if (! open(GOCR, " /opt/local/bin/gocr |") {

close(GOCR);


You should check the return value from pipe-opens too:

close(GOCR) or die "problem running gocr $?, $!";
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,222
Members
46,810
Latest member
Kassie0918

Latest Threads

Top