Perl calls other Program Methods

Source: Internet
Author: User

1. System ("command ");
Use this command to enable a sub-process to execute the command in quotation marks. The parent process will wait until the sub-process ends and continue to execute the following code.

2. Exec ("Command ");
The effect is similar to that of the system command. The difference is that the sub-process is not enabled, but the parent process is replaced. Therefore, after the command in quotation marks is executed, the process ends. Generally used in combination with fork.

3. 'command ';
An external command can be called with backquotes to capture its standard output, return by line, and a carriage return is attached at the end of each line. Variables in the back quotes are interpolated as their values during compilation.

4. Open list "LS-L | ";
Open more "| more ";
@ List =;
Print more @ list;
Close (list );
Close (more );
Use a file handle with an MPS queue to execute External commands, which is similar to reading and writing files. Data can be read from the output of External commands, or output to external commands as input.

5. defined (my $ pid = fork) or die "can not fork: $! \ N ";
Unless ($ PID ){
Exec ("date ");
}
Waitpid ($ PID, 0 );
If fork is used, the code after both the sub-process and the parent process are enabled. Fork in the parent process returns a non-zero number, and the sub-process returns zero.
The code above completes the same functions as system ("date. Fork can perform more complex process operations than simply calling external commands by system.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.