wget Failing in php exec

Go To StackoverFlow.com

1

I have a little script that I'm trying to run but it dies at exec()

<pre><?php

    ini_set("display_errors", 1);

    $command = "wget --save-cookies cookies.txt \
                --post-data '***' \
                --keep-session-cookies \
                http://site.com/ac_login.php;

                wget --load-cookies cookies.txt \
                --keep-session-cookies \
                -p http://site.com/ac_landing.php;";

    exec($command, $output) or die('fail');

    foreach ($output as $num => $line) {

        echo $num + 1 . ": " . $line . "\n";
    }

?></pre>

If I remove the \ at the end of each line I get a response of

1: wget: missing URL
2: Usage: wget [OPTION]... [URL]...
3: 
4: Try `wget --help' for more options.
5: wget: missing URL
6: Usage: wget [OPTION]... [URL]...
7: 
8: Try `wget --help' for more options.

I tried moving all the commands to one line but then it dies again. What am I doing wrong? How can I retrieve the error in this script? Adding in a 3rd param for result in exec returns empty.

I'm using this for reference https://stackoverflow.com/a/1432161/763468

The commands work in an SSH console.

2012-04-03 21:14
by Steve Robbins
print output and paste in console, however you can put all in 1 line concatenating with $var .= "" and remove the last ; from the command as Thomas Wright writed belo - ZiTAL 2012-04-03 21:24
There is no output because of the dieSteve Robbins 2012-04-03 21:43
i mean print the wget command, not the result and then copy to console to tr - ZiTAL 2012-04-04 07:22
Copying and pasting the commands into console works. The best I can do is for now is have cron run the script, it will work then - Steve Robbins 2012-04-04 19:24
curl has a php module: http://php.net/manual/en/book.curl.php i usually use this and works very well : - ZiTAL 2012-04-05 08:59


2

First off, I don't think you need that semi-colon after the file name

-p http://site.com/ac_landing.php;

to

-p http://site.com/ac_landing.php
2012-04-03 21:19
by Thomas Wright
Other than that, it looks like using wget with exec() seems to generate frequent problems. There are quite a few similar posts on StackOverflow. You might want to take a look at some of those as well. http://stackoverflow.com/questions/2528466/how-to-run-wget-from-php-so-that-output-gets-displayed-in-the-browser-window http://stackoverflow.com/questions/9889099/wget-on-windows-through-php-exec-doesnt-wor - Thomas Wright 2012-04-03 21:23


0

Did you try one command per exec call?

exec("wget --save-cookies cookies.txt --post-data '***' --keep-session-cookies http://site.com/ac_login.php");
exec("wget --load-cookies cookies.txt --keep-session-cookies -p http://site.com/ac_landing.php");
2012-04-03 21:21
by Alexander
Ads