Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to solve the problem that system() does not return output in php

2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly introduces how to solve the problem that system () does not return output in php. It is very detailed and has a certain reference value. Interested friends must read it!

The solution to system () not returning output in php: redirect standard error to standard output by appending [2 > & 1] to the command, for example, [exec ('some_command-- option 2 > & 1 option $output,$ ret);].

This article operating environment: windows10 system, php 7, thinkpad T480 computer.

Recently, I accidentally found that exec () works well when executing a common command such as' ls', for example:

Exec ('ls',$ output, $retval); var_dump ($output,$ retval); / / $output contains an array of file names, retval = 0

But when I tried to execute another program, I couldn't get the output, as follows:

Exec ('some_command-- a parameterized var_dump $output,$ retval); var_dump ($output,$ retval); / / $output contains an empty array, ending with $retval = 0

Some lines are printed when the command is executed directly from the command line. I know that the command was executed successfully, and I can see the results (some file updates, data additions, etc.), but I can't see the output.

The exec () function will capture only standard output. I'm not sure that standard errors are always sent to the apache error log, but it seems possible.

If you do not need to use the unix system, we can actually redirect standard error to standard output by appending 2 > & 1 to the command, so that the problem can be solved, for example:

Exec ('some_command-- option 2 > & 1 output,$ ret); the above is all the contents of this article entitled "how to solve the problem that system () does not return output in php". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report