php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #63731 shell_exec() cannot run some commands
Submitted: 2012-12-08 23:37 UTC Modified: 2012-12-09 12:05 UTC
From: scott at smashcat dot org Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 5.4.9 OS: Linux
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: scott at smashcat dot org
New email:
PHP Version: OS:

 

 [2012-12-08 23:37 UTC] scott at smashcat dot org
Description:
------------
When attempting to call the zip command from php, it silently fails. Other commands to create and delete files etc work fine. Using correct path to zip etc. No errors, just fails. Running same command from terminal works.

Test script:
---------------
$zip=`which zip`;
$res=shell_exec("$zip test.zip test.txt");


Expected result:
----------------
zip file should be created

Actual result:
--------------
Nothing. No errors, although the response variable $res contains what appears to be part of the zip file data. Seems like the output from zip is not going to the file, but being sent to the virtual terminal.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-12-08 23:43 UTC] rasmus@php.net
Sorry, this has nothing to do with PHP. All PHP does is call popen() here which 
creates a pipe and forks a shell to run the command. To debug it try switching to 
your web server user id from the command line and trying it and if you are really 
stuck write a little popen() wrapper in C and try to figure out where it is 
failing. My guess is that it is a permissions issue.
 [2012-12-08 23:43 UTC] rasmus@php.net
-Status: Open +Status: Not a bug
 [2012-12-09 12:05 UTC] scott at smashcat dot org
Yep, was totally user error - output from $zip=`which zip` adds a linefeed which was not being trimmed, so the command was sending zip to stdout. My bad! Removing...
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon Jul 14 18:01:33 2025 UTC