larsen has asked for the wisdom of the Perl Monks concerning the following question:

I am writing a Perl script that has to do the following:
  1. Fetch some stuff from another site
  2. Parse that stuff and produce some Javascript code
  3. Return Javascript code on standard output

This script, as you could guess, will be called from another automatically generated page, in such a way...

print $query->start_html( -title => 'Some title', -script => { -language => 'Javascript', -src => 'my_script.pl' } );

or something like this.

The problem is in the first step. Since the HTML code is simply ugly, I'm using lynx to get a text-dump of the page, as some good monks suggested me in this thread (Reverse engineering HTML).

So the first lines of my_script.pl are something like:

my $query = new CGI; print $query->header("text/plain"); my $body = `lynx -dump some_url_here`;

But this doesn't work. I've add print $body after this snippet and I've seen this (for me, mysterious) error message (the string after /var/www/ changes every time I run the script):

/var/www/XCjrzA: Permission denied

I think it could be a problem in the configuration of Apache, so I apologize in advance for offtopic question. I also add that I tried to use pipes to read lynx's output, but it didn't worked, with the same error-message.

Replies are listed 'Best First'.
Re: Problems with backticks (maybe with Apache configuration)
by busunsl (Vicar) on Jun 22, 2001 at 14:24 UTC
    It seems you are missing the permission to write to /var/www.

    Look here for altering the location of lynx tempfiles.

Re: Problems with backticks (maybe with Apache configuration)
by perigeeV (Hermit) on Jun 22, 2001 at 15:33 UTC
    Lynx uses temp files liberally. Even though -dump is supposed to output to STDOUT, it still creates intermediate temp files. It writes those temp files to the user's home directory. The problem is you're probably running as 'nobody'. Try running:

    lynx -trace -tlog -dump http://foo.bar 2>/tmp/lynx.tracefile

    Search for LYOpenTemp in the tracefile.

    You could muck about with Lynx's environment variables or even sudo, but you might just use LWP::Simple.

Re: Problems with backticks (maybe with Apache configuration)
by Zaxo (Archbishop) on Jun 22, 2001 at 14:28 UTC

    I think you are confused about how your script should be called. The client-side script tag is inconsistent:

    -script => { -language => 'Javascript', -src => 'my_script.pl' }

    while the printing of headers in my_script.pl indicates that you mean it as server-side code.

    A link to my_script.pl's URI should be enough.

    The "Permission denied" message is likely from bad file mode settings or cgi setup.

    After Compline,
    Zaxo

    Update: See larsen's reply. I misunderstood and my theory is all wrong. It could have been right so I'll let the post stand by itself without any help from facts ;-)

      I've badly explained the structure. A script, let's say a.pl, produce a dinamycally page that, among other things, needs some dinamically generated Javascript code. So a.pl has these lines:

      -script => { -language => 'Javascript', -src => 'my_script.pl' }
      in order to call my_script.pl. So the text/plain header is written by my_script.pl: it produces Javascript code, indeed. Maybe I could tell you only about my_script.pl, that is what's causing the problem, but I thought it was better to specify all the structure of script. I hope I've explained things more clearly now. Thank you