system

How do I call a system or third party program from perl?

You want to call another program from your perl program.

Solution 1: system call

You can call any program like you would from the command line using a system call. This is only useful if you do not need to capture the output of the program.

Or if you don’t want to involve the shell:

You’ll need to bitshift the return value by 8 (or divide by 256) to get the return value of the program called:

Solution 2: qx call

If you need to capture the output of the program, use qx.

Or if the output has multiple lines (e.g. the output of the “who” command can consist of many lines of data):

You can also use backticks (`) to achieve the same thing:

See also

Run

and refer to the qx section.

Scroll to Top