In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces "the use of PHP command line shell _ exec ()". In daily operation, I believe many people have doubts about the use of PHP command line shell _ exec (). The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful to answer the doubts about the use of PHP command line shell _ shell ()! Next, please follow the editor to study!
PHP CLI SAPI allows you to develop shell scripts, even desktop-based scripts, that are supported by PHP. In fact, you can use the PHP command line to run the tool. In this way, PHP developers can be as efficient as Perl, AWK, Ruby, or shell programmers. This article explores the tools built into PHP to give you an understanding of the underlying shell environment and file system in which PHP runs. PHP provides a number of functions for executing external commands, including shell_exec (), exec (), passthru (), and system (). These commands are similar, but provide different interfaces for the external programs you are running. All of these commands derive from a child process that runs the commands or scripts you specify, and each child process captures the command output as it is written to standard output (stdout).
Shell_exec ()
The shell_exec () command line is really just a variation of the backapostrophe (`) operator. If you have written shell or Perl scripts, you know that you can capture the output of other commands inside the backapostrophe operator. For example, listing 1 shows how to use an apostrophe to get a word count for each text (.txt) in the current directory.
PHP Command Line Overview
Listing 1. Use reverse apostrophes to calculate the number of words
#! / bin/sh number_of_words= `wc-w * .txt` echo $number_of_words # result would be something like: # 165readme.txt 388 results.txt 588 summary.txt # and so on....
In your PHP script, you can run this simple command in shell_exec (), as shown in listing 2, and get the desired results. It is assumed that there are some text files in the same directory.
Listing 2. Run the same command in shell_exec ()
Note that using only the post-apostrophe operator will get the same result, as shown below.
Listing 3. Use only the apostrophe operator
Listing 4. A simpler method
It's important to know that you can do a lot of things with the UNIX command line and shell scripts. For example, you can use vertical bars to connect commands. You can even use operators to create shell scripts in it and call only shell scripts (with or without parameters as needed). For example, if you only want to count the words of the first five text files in that directory, you can use a vertical bar (|) to connect the wc and head commands. In addition, you can put the output inside the pre tag so that it can be more beautifully rendered in the Web browser, as shown below.
Listing 5. More complex shell commands
At this point, the study of "the use of shell _ exec () on the PHP command line" is over. I hope I can solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.