Stephan Kristyn Stephan Kristyn - 2 months ago 22
Git Question

Git Hook PHP Script: No Output

I have this Script

php-pull-script.php
written:

<?php

$output1 = shell_exec('git pull');
$output2 = shell_exec('pkill java');
$output3 = shell_exec('mvn package');
$output4 = shell_exec('java -jar ./target/compute-0.0.1-SNAPSHOT.jar');

echo "<pre>$output1</pre>";
echo "<pre>$output2</pre>";
echo "<pre>$output3</pre>";
echo "<pre>$output4</pre>";


?>


When executing in shell, I am not seeing any output in order to verify that it is running. I am not sure at all it is working. Is there a better way to do this automation script?

Answer

How to send of the java command with shell_exec and leave it running in background (Is & possible with shell exec)?

test.php

 <?php
 shell_exec('test.sh');

test.sh

 echo "Do something"
 /bin/sh -c 'sleep 10' >> /dev/null 2>&1 &

 exit 0
  • /dev/null can be also a path to an logfile
  • All pathes here and in phpscript should be absolute, like: /path/tomy/test.sh

Here the test.php doesnt wait 10 seconds for the subcall.

Hope that helps a little ;)

Comments