backticks not running application (please help!)

Discussion in 'Perl Misc' started by Dan, Jan 30, 2006.

  1. Dan

    Dan Guest

    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
    Dan, Jan 30, 2006
    #1
    1. Advertising

  2. Dan

    Guest

    "Dan" <> wrote:
    > 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

    --
    -------------------- http://NewsReader.Com/ --------------------
    Usenet Newsgroup Service $9.95/Month 30GB
    , Jan 30, 2006
    #2
    1. Advertising

  3. Dan

    Dan Guest

    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
    Dan, Feb 1, 2006
    #3
  4. Dan

    Dan Guest

    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?


    >> 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.
    Dan, Feb 1, 2006
    #4
  5. Dan

    Dan Guest

    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.
    Dan, Feb 1, 2006
    #5
  6. Dan

    Anno Siegel Guest

    Dan <> wrote in comp.lang.perl.misc:
    > 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
    --
    If you want to post a followup via groups.google.com, don't use
    the broken "Reply" link at the bottom of the article. Click on
    "show options" at the top of the article, then click on the
    "Reply" at the bottom of the article headers.
    Anno Siegel, Feb 1, 2006
    #6
  7. Dan

    Dan Guest

    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:


    > 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...
    Dan, Feb 1, 2006
    #7
  8. Dan

    Anno Siegel Guest

    Dan <> wrote in comp.lang.perl.misc:

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

    > >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,
    >
    > 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
    --
    If you want to post a followup via groups.google.com, don't use
    the broken "Reply" link at the bottom of the article. Click on
    "show options" at the top of the article, then click on the
    "Reply" at the bottom of the article headers.
    Anno Siegel, Feb 1, 2006
    #8
  9. Dan

    Dan Guest

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


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


    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
    Dan, Feb 1, 2006
    #9
  10. Dan

    Anno Siegel Guest

    Dan <> wrote in comp.lang.perl.misc:
    > >> >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,

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

    >
    > 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
    --
    If you want to post a followup via groups.google.com, don't use
    the broken "Reply" link at the bottom of the article. Click on
    "show options" at the top of the article, then click on the
    "Reply" at the bottom of the article headers.
    Anno Siegel, Feb 1, 2006
    #10
  11. Dan

    Guest

    "Dan" <> wrote:
    > 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

    --
    -------------------- http://NewsReader.Com/ --------------------
    Usenet Newsgroup Service $9.95/Month 30GB
    , Feb 1, 2006
    #11
  12. Dan

    Big and Blue Guest

    Dan wrote:

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


    --
    Just because I've written it doesn't mean that
    either you or I have to believe it.
    Big and Blue, Feb 2, 2006
    #12
  13. Dan

    Guest

    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).
    , Feb 3, 2006
    #13
  14. Dan

    Dan Guest

    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
    Dan, Feb 3, 2006
    #14
  15. <> wrote:

    > 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 $?, $!";


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
    Tad McClellan, Feb 4, 2006
    #15
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Kristina Clair
    Replies:
    0
    Views:
    660
    Kristina Clair
    Aug 27, 2004
  2. KK
    Replies:
    2
    Views:
    524
    Big Brian
    Oct 14, 2003
  3. Replies:
    1
    Views:
    386
    Richard Brown
    May 23, 2006
  4. Steven Brent

    Backticks: What up?

    Steven Brent, Apr 28, 2004, in forum: Python
    Replies:
    6
    Views:
    326
    Steve Holden
    Apr 28, 2004
  5. Sam Stephenson
    Replies:
    9
    Views:
    223
    Caleb Clausen
    Nov 7, 2005
Loading...

Share This Page