468,720 Members | 1,647 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,720 developers. It's quick & easy.

How to get output of an exec call?

Hi,

I'm using PHP 5. Assuming there are no errors, how do I get the
output of an exec call? I'm trying

$cmd = 'strings < ' . escapeshellarg($file) . ' | sed -
n \'s|.*/Count -\{0,1\}\([0-9]\{1,\}\).*|\1|p\' | sort -rn | head -n
1';
exec("$cmd 2>&1", $output, $return);
if ($return != 0) {
$output = join("<BR>\n", $output) . "<BR>\n";
return -1;
} // if
$count = intval(join("", $output));
return $count;

But the $output array is empty. I have printed out the $cmd var and
verified that I can run it on my shell.

Thanks for any feedback, - Dave
Aug 8 '08 #1
1 1752
la***********@zipmail.com wrote:
Hi,

I'm using PHP 5. Assuming there are no errors, how do I get the
output of an exec call? I'm trying

$cmd = 'strings < ' . escapeshellarg($file) . ' | sed -
n \'s|.*/Count -\{0,1\}\([0-9]\{1,\}\).*|\1|p\' | sort -rn | head -n
1';
exec("$cmd 2>&1", $output, $return);
if ($return != 0) {
$output = join("<BR>\n", $output) . "<BR>\n";
return -1;
} // if
$count = intval(join("", $output));
return $count;

But the $output array is empty. I have printed out the $cmd var and
verified that I can run it on my shell.

Thanks for any feedback, - Dave
Redirection is performed by the command processor, not the OS. To use
it, you must invoke the command processor.

For an alternative, look at proc_open(), which can handle the
redirection directly.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Aug 9 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by DonMiche | last post: by
3 posts views Thread by seven.reeds | last post: by
1 post views Thread by btysgtmajor | last post: by
3 posts views Thread by ajh | last post: by
2 posts views Thread by jdbartlett | last post: by
1 post views Thread by CARIGAR | last post: by
1 post views Thread by Oskars | last post: by
9 posts views Thread by bryonone | last post: by
reply views Thread by zhoujie | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.