in reply to Re: LWP::Simple Empty File
in thread LWP::Simple Empty File

Thanks for the quick response. I added the status_message snippet and get "OK". This works fine on my Linux machine but is giving me an empty file on Windows 7 machine. I installed Strawberry Perl 5.10.1.5 and have version LWP 5.837. I am sure it is something stupid that I am missing.

#!/usr/bin/perl use strict; use warnings; use LWP::Simple; my $rc = getstore('http://www.perlmeme.org', 'some_local_fi +le'); print status_message($rc), "\n"; getstore('http://www.perlmeme.org', 'some_local_file'); exit 0;

Replies are listed 'Best First'.
Re^3: LWP::Simple Empty File
by Marshall (Canon) on Mar 04, 2012 at 04:34 UTC
    As per suggestion from Corion, what happens when you run this?

    The HTTP return code is not available for get() without using the LWP::UserAgent OO interface, but this 3 lines of code should ensure that your Windows box is actually getting something (runs on my XP Perl 5.10.1). If this prints something, then it comes down to probable file naming or permission errors in your getstore() statement.

    It is hard for me to understand how a new file could be created with no content if the RC is 'OK'. That would imply that you do have the permission to create the file in the first place and therefore have permission to write to it!
    Testing Note: delete your "blank" output file between runs to make sure that it is actually being created and not an artifact of some previous run.

    Anyway run this simple test and report back.

    #!/usr/bin/perl -w use strict; use LWP::Simple; my $content = get("http://perlmonks.org/?node_id=957704"); die "blank content" unless defined $content; print $content;

      Nothing is printed when I run the test above. I do notice that there is a very slight lag before it goes back to the command prompt. Anything else I should try?

        Odd. Let's make sure we are talking about the same thing.
        Save the program as for example: testLWP.pl
        From the command line type: perl testLWP.pl
        I am thinking that something is wrong in your Windows Perl environment.
        There are some "tricks" about this - related to file associations.
        Invoke Perl explicitly in the command line "perl testLWP.pl".

        In theory, we should be able to figure out why this code (3 lines) is not running on your machine.
        I think something is wrong that is unrelated to LWP.

        Forgive me for asking this, but can you run "helloWorld.pl"?

        #!/usr/bin/perl -w use strict; print "Hello World!!\n";
Re^3: LWP::Simple Empty File
by GrandFather (Saint) on Mar 03, 2012 at 21:51 UTC

    Works fine for me fetching http://perlmonks.org/?node_id=957704 on Windows XP using ActiveState Perl 5.10.1. I doubt very much that it is either the build of Perl or the OS.

    True laziness is hard work