php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #22926 Cannot call PHP from shell_exec
Submitted: 2003-03-27 07:45 UTC Modified: 2003-04-01 01:41 UTC
From: phpbugs at bob7 dot com Assigned:
Status: Not a bug Package: Program Execution
PHP Version: 4.3.1 OS: Windows 2000 server
Private report: No CVE-ID: None
 [2003-03-27 07:45 UTC] phpbugs at bob7 dot com
The following does not work.  It spawns scores of processes, which fortunately all die after 30 seconds.
<?
echo shell_exec("(path to php)/php.exe -h");
?>

I looked at the bug reports about possibly needing command.com but these do not work either: (same result)
<?
echo shell_exec("command -c (path to php)/php.exe -h");
?>
<?
echo shell_exec("CMD /C (path to php)/php.exe  -h");
?>

Why would I want to do this?  To send html email using the PEAR mime mail class, i.e.
<?
$htmlBody = shell_exec("(path to php)/php.exe mimebody.php?param1=yada");
//rest of code to send mail...
?>

I downloaded and installed the standard windows installer, and the path to php is C:\Inetpub\PHP

I have the same problem using back ticks as well.

Thanks very much for looking at this.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-03-27 07:51 UTC] edink@php.net
Could you please try CLI version of PHP.EXE? It comes in the cli directory of the standard ZIP distribution.
 [2003-03-31 10:47 UTC] phpbugs at bob7 dot com
I repeated the test using the CLI interface and was able to get 'php -h' to run.  

I also see that I can use the new streams functionality to create HTML mail bodies. The problem with the streams approach is that (I believe) the .php files need to be in the document tree, so if I go that route, I have to add authentication. 

Perhaps there is or you guys may be planning a way that allows http streams from outside the doc tree?

Thanks again,
-Bob
 [2003-03-31 17:32 UTC] pollita@php.net
Works w/ CLI, not PHP Bug => Bogus

As to using a stream to get the output of processing another PHP file:  Unfortunately the document you want processed (using this method) MUST be in a publicly accessable document tree.

All the php stream does is pretend its a browser making a page request.

What you *can* do, if you want to be able to do this the easy way but not have the document be publicly accessable is give it a password.

// In your main script:
<?php
  $message = file_get_contents("http://localhost/generateemail.php?password=secret");
?>


// In generateemail.php:
<?php
  if ($_GET['password'] != 'secret') die("Don't hack!");
  // Do the rest of your magic
?>


Hope that helps.
 [2003-04-01 01:41 UTC] phpbugs at bob7 dot com
Your comments are very helpful.  Thanks! 

I hope this helps the next guy too.  

One thing to remember is to copy the php4ts.dll file into the CLI directory if it is on the machine's path. Otherwise shell_exec returns an empty string.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Mar 29 07:01:28 2024 UTC