PHP: Why isn't exec() returning output? -
i'm writing php script used check network connections linux shell command ping calling php's exec():
<?php // bad ip domain testing. $domain_bad = "lksjdflksjdf.com"; $ip_address = $domain_bad; exec("ping -c 1 $domain_bad", $output, $return_var); var_dump($return_var); echo "return_var is: $return_var" . "\n"; var_dump($output); exit; ?> i'm not getting output error message ping in $output i'm expecting:
$ php try.php ping: unknown host lksjdflksjdf.com int(2) return_var is: 2 array(0) { } if domain domain, such yahoo.com, $output has output ping in array. if it's error such 'ping: unknown host lksjdflksjdf.com' doesn't returned $output array.
why happening , there better method this?
you should redirect stderr stdout.
to that, change exec() call this:
exec("ping -c 1 $domain_bad 2>&1", $output, $return_var); more info 2>&1 meaning here.
Comments
Post a Comment