0

I have to execute a shell script when pressing a button on a web page. For this I'm using php so I have created a button in the file test.php

<form method="get" action="buildMaster.php">
    <input type="submit" value="Build Master" id="btnMaster">
</form>

when pressing the button, the php buildMaster.php is called:

<?php
    shell_exec('touch /Users/testUser/xxx');
?>

To test, I just touch a file to see if the script is called but nothing happens. The browser (Safari on Mac Lion) goes to buildMaster.php but nothing happens. What am I doing wrong ?

3
  • 1
    print the shell_exec() output and check what you are getting Commented Mar 5, 2014 at 12:08
  • Write any static html content in buildMaster.php and test it Commented Mar 5, 2014 at 12:09
  • I guess I have to add "$output = shell_exec(...)" to the php, but how do I see the output ? I've never worked with web/php before. Once the action has been called, where do I check the output ? Commented Mar 5, 2014 at 12:14

2 Answers 2

1

Try this:

<?php
$output = shell_exec('ls -lart');
echo "<pre>$output</pre>";
?>

And you'll see the output of your command

Also look to documentation: https://www.php.net/shell_exec - this function might be disabled if PHP is running in save mode.

Sign up to request clarification or add additional context in comments.

2 Comments

Ok, ls writes the list of files to the browser so the php actually works. But the touch does nothing and outputs nothing.
Touch command outputs nothing in the shell. Check if the file is created or its timestamp has changed on webserver.
0

Ok, found out. I have to redirect stderr to stdout.

<?php
    $output = shell_exec('touch /Users/testUser/xxx 2>&1');
    echo "<pre>$output</pre>";
?>

The output: touch: .... Permission denied

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.