php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #37316 exec() don't work
Submitted: 2006-05-04 23:01 UTC Modified: 2010-02-17 14:18 UTC
Votes:3
Avg. Score:5.0 ± 0.0
Reproduced:3 of 3 (100.0%)
Same Version:1 (33.3%)
Same OS:1 (33.3%)
From: ale5000 at tiscali dot it Assigned:
Status: Not a bug Package: Unknown/Other Function
PHP Version: 5.1.4 OS: Windows XP
Private report: No CVE-ID: None
 [2006-05-04 23:01 UTC] ale5000 at tiscali dot it
Description:
------------
I have PHP 5.1.3 on IIS server 5.1 installed as ISAPI and exec() says:

Warning: exec() [function.exec]: Unable to fork [tasklist /FI "PID eq 2624" /FO LIST]

Reproduce code:
---------------
if( !function_exists("memory_get_usage") )
	{
		function memory_get_usage()
		{
			$pid = getmypid();
			if ( substr( PHP_OS, 0, 3 ) == 'WIN' )
			{
				$output = array();

				exec( "tasklist /FI \"PID eq ".$pid."\" /FO LIST", $output );
				return preg_replace( '/[^0-9]/', '', $output[5] ) * 1024;
			}
			else
			{
				exec( "ps -eo%mem,rss,pid | grep ".$pid, $output );
				$output = explode("  ", $output[0]);
				return $output[1] * 1024;
			}
		}
	}

Expected result:
----------------
The memory used by the script.

Actual result:
--------------
Warning: exec() [function.exec]: Unable to fork [tasklist /FI "PID eq 2624" /FO LIST]

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2006-05-05 18:52 UTC] mike@php.net
See if "tasklist" is in your path and executable or try pecl/win32ps.
 [2006-05-05 23:00 UTC] ale5000 at tiscali dot it
Yes, it is in the path and it is executable.
I have also tried:
  echo system("c:\windows\system32\hostname.exe");
same result.
 [2006-05-22 00:49 UTC] jon at thejon dot org
You need to make sure that the file has executable permission for your web user. It may also need executable permission for cmd.exe, but I would think this is very large security hole... I hope there is another way with allowing access to cmd.exe.
 [2006-06-01 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 [2006-06-02 01:50 UTC] mpelzsherman at yahoo dot com
I was able to get this to work by setting the "anonymous" user in IIS to a "real" user account rather than the IUSR account.
 [2010-02-17 14:18 UTC] pajoye@php.net
Quick note here. It is necessary to give a given IUSR_* the permission to use cmd.exe (%COMSPEC%). It is recommended not to do it as it may introduce security issues, obviously. But if you really want to do it, use:

cacls %COMSPEC% /E /G IUSR_xxxx:R

Close the bug as it is a configuration issue.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Mon May 06 10:01:31 2024 UTC