1

I have a simple php script that passes a couple variables to and runs a python script with the shell_exec command. When I run this php script from the shell it works just fine. However, when I run the php script from the browser, it causes the server to crash. I've tried this with both exec and shell_exec php functions. Why would it matter whether I run the script form the shell or the browser?

For the record, I can run other commands from the browser successfully, such as "tar -xcpvf path.tar.gz"

Here is the php script that has trouble from the browser:

    <?php
    $inputs = array(    
    'location' => "Los Angeles",
    'date' => '11/01/2012',
    );
    $cmd = 'python simple.py '.$inputs['location'].' '.$inputs['date'];
    $results = shell_exec($cmd);
    echo $results;      
    ?>

Any help will be much appreciated. Thanks!

1
  • Check your error log - what kind of error do you get ? Commented Sep 14, 2012 at 23:05

1 Answer 1

2

Without the error log, I can't be certain, but it looks like you're not quoting your parameters. So the actual command you're passing into shell_exec is:

python simple.py Los Angeles 11/01/2012

What you're (presumably) wanting is this:

python simple.py "Los Angeles" "11/01/2012"

To get that, your $cmd line should look like this:

$cmd = 'python simple.py "'.$inputs['location'].'" "'.$inputs['date'].'"';
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.