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
 [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

Add a Patch

Pull Requests

Add a Pull Request

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-2019 The PHP Group
All rights reserved.
Last updated: Sat Jul 20 07:01:25 2019 UTC