1

my terminology my be off, but here goes:

lets assume one executes:

/bin/somecommand

using exec or system in php

the above command returns 'exit code' (this is the terminology that may be off) '1'.

is it possible to fetch this value via php?

if possible, do this without using a 'parent' bash script. we would love to be able to fetch this directly from php rather then having to run a parent bash script, and have that script echo out the exit code.

thanks!

1 Answer 1

7

The manual for exec() shows that you can provide an optional third argument to collect the return status (exit code). Similarly for system(), a second optional argument.

Example from that page:

<?php
echo '<pre>';

// Outputs all the result of shellcommand "ls", and returns
// the last output line into $last_line. Stores the return value
// of the shell command in $retval.
$last_line = system('ls', $retval);

// Printing additional info
echo '
</pre>
<hr />Last line of the output: ' . $last_line . '
<hr />Return value: ' . $retval;
?>
Sign up to request clarification or add additional context in comments.

1 Comment

doh! my bad i should have read this in more detail. sigh. regardless, correct answer! thanks!

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.