Perl Array exec() and system() Function - Quick Tutorial

Person with laptop
Image Source/Photodisc/Getty Images
 exec(PROGRAM);
 $result = system(PROGRAM); 

Both Perl's exec() function and system() function execute a system shell command. The big difference is that system() creates a fork process and waits to see if the command succeeds or fails—returning a value. exec() does not return anything, it simply executes the command. Neither of these commands should be used to capture the output of a system call.

If your goal is to capture output, you should use the backtick operator:

 $result = `PROGRAM`; 
Format
mla apa chicago
Your Citation
Brown, Kirk. "Perl Array exec() and system() Function - Quick Tutorial." ThoughtCo, Oct. 23, 2017, thoughtco.com/perl-array-exec-system-function-tutorial-2641183. Brown, Kirk. (2017, October 23). Perl Array exec() and system() Function - Quick Tutorial. Retrieved from https://www.thoughtco.com/perl-array-exec-system-function-tutorial-2641183 Brown, Kirk. "Perl Array exec() and system() Function - Quick Tutorial." ThoughtCo. https://www.thoughtco.com/perl-array-exec-system-function-tutorial-2641183 (accessed November 22, 2017).