Use shell commands and pipelines in Perl

Source: Internet
Author: User

There are three methods to use shell commands in Perl:

  • System Functions
  • ''
  • QX {}

First, the system function format is as follows:

System ("command ");

If the command runs normally, 0 is returned; otherwise, a non-zero value is returned.

The disadvantage of this method is that the shell command output cannot be directly captured into the Perl program.

Method 2: Use reverse quotation marks ''to directly capture the shell command output to the Perl Program (that is, its return value)

For multi-row output, assign it to the array variable, as shown in figure

@ A = 'LS-al ';

Method 3: Use QX {}. This method is applicable when the command contains multiple backquotes. In addition, curly braces {} can also be replaced with other symbols.


Pipelines in Perl are considered to be readable and writable files, as shown in

Open (rhandle, "ls-Al | sort |"); // rhandle is the Read File handle, and the part that reads the output of the sort command is open (whandle, "| more "); // whandle is the Write File handle. The written content is sent to the more command through the pipeline for paging display.
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.