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.

Community
  • 1
  • 1
Steve Robbins
  • 13,672
  • 12
  • 76
  • 124
  • 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 below – ZiTAL Apr 03 '12 at 21:24
  • There is no output because of the `die` – Steve Robbins Apr 03 '12 at 21:43
  • i mean print the wget command, not the result and then copy to console to try – ZiTAL Apr 04 '12 at 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 Apr 04 '12 at 19:24
  • curl has a php module: http://php.net/manual/en/book.curl.php i usually use this and works very well :) – ZiTAL Apr 05 '12 at 08:59

2 Answers2

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
Thomas Wright
  • 1,309
  • 1
  • 9
  • 15
  • 1
    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-work – Thomas Wright Apr 03 '12 at 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");
Alexander
  • 23,432
  • 11
  • 63
  • 73