Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

External program execution...or rather non-execution

Status
Not open for further replies.

dmg2206

MIS
Feb 15, 2002
54
US
I am trying to execute an external command on my Linux (RedHat 7.2) machine through PHP. Unfortunately, it doesn't seem to be working.

Here is my web page's source code:

Code:
<?php $cmd = &quot;ls /home/myhome > /home/dgable/ls_results.txt&quot;;
      $results = shell_exec($cmd);
?>
<html>
 <body>
  <?php echo $results;
  ?>
 </body>
</html>

That returns a blank page, and /home/myhome/ls_results.txt does not appear.

Trying a different function:
Code:
<?php $cmd = &quot;ls /home/myhome > /home/myhome/ls_results.txt&quot;;
      $last_line = exec($cmd, $results, $ret_val);
?>
<html>
 <body>
 <?php echo &quot;Last Line: &quot; . $last_line . &quot;<br>&quot;;
       echo &quot;Results: &quot; . implode(&quot;<br>&quot;, $results) . &quot;<br>&quot;;
       echo &quot;Return Value: &quot; . $ret_val;
 ?>
 </body>
</html>

The web page that returns looks like this:

Last Line:
Results:
Return Value: 1

safe_mode is off. Any ideas?
 
You're piping your command to a file. It is correct that no output would be returned to PHP. So echoing $results should output nothing.

You're saying that after the script is run, the file ls_results.txt does not appear on the filesystem?

Does the user as which your web server runs have permission to write to the directory /home/myhome ? Does that directory exist?

Want the best answers? Ask the best questions: TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top