php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77645 Error in the exec function
Submitted: 2019-02-21 09:40 UTC Modified: 2019-06-14 12:11 UTC
From: ailiangkuai at qq dot com Assigned: sjon (profile)
Status: Not a bug Package: Unknown/Other Function
PHP Version: 7.1.26 OS: CentOS release 6.8 (Final)
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: ailiangkuai at qq dot com
New email:
PHP Version: OS:

 

 [2019-02-21 09:40 UTC] ailiangkuai at qq dot com
Description:
------------
---
From manual page: https://php.net/function.system
---
i want execute linux shell via php.if the shell works fine,the $output will be filled with every line of output from the shell script.but if shell script has error,$output is filled whith nothing. i have used the func of python which is commands.getoutput,Get the result regardless of whether the script has an error.

Test script:
---------------
<?php
$lastOutput = exec("gunzip < /backup-files/test.sql.gz | mysql -u*** -p'***' --host=localhost --database=test",$output,$return_var);


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2019-06-14 12:11 UTC] sjon@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: sjon
 [2019-06-14 12:11 UTC] sjon@php.net
If you want to return errors, you should append 2>&1 to your command - as all system calls do not include stderr in their output by default.
You could also switch to proc_open which allows you to retrieve stderr separately
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Jul 02 01:01:34 2025 UTC