Skip to content

Instantly share code, notes, and snippets.

@jocoonopa
Last active December 28, 2015 22:59
Show Gist options
  • Save jocoonopa/7575993 to your computer and use it in GitHub Desktop.
Save jocoonopa/7575993 to your computer and use it in GitHub Desktop.
<?php
echo "system<br/>";
echo "<pre>會將內容直接輸出:</pre>";
echo "<pre>";
$last_line = system('ls', $status_code);
echo "</pre>";
echo "<pre>只會有最後一行:".$last_line."</pre>";
echo "<pre>狀態碼:".$status_code."</pre>";
echo "<hr/>passthru:<br/><pre>";
passthru ('echo $PATH');
echo "</pre><br/>";
echo "<hr/>exec<br/>";
exec( 'ls', $output, $status_code);
echo "<pre>儲存成陣列:</pre>";
echo "<pre>";
print_r( $output );
echo "</pre>";
echo "<pre>狀態碼:".$status_code."</pre>";
echo "<hr/>shell_exec:<br/>";
$output = shell_exec( 'ls' );
echo "<pre>儲存成文字:</pre>";
echo "<pre>";
print_r( $output );
echo "</pre>";
echo "<hr/>popen:<br/>";
echo "<pre>類似於fopen</pre>";
$pipe = popen("/bin/ls", 'r');
while ($s = fgets($pipe, 1024) ){
$arr[] = $s;
}
pclose( $pipe );
echo "<pre>";
print_r ($arr);
echo "</pre>";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment