I can thought that it will open a shell, execute the parameter (shell command) and return the result in a scalar.
But, execute system function in a Perl script is faster than a shell command.
It will call this command in C?
If yes, what’s the difference between
rmdir foo
and
system('rmdir foo');
The difference between the two is that the second one will open (fork) a child process (which will be the rmdir command) while the first one will make a direct Unix system call using the API without opening a process. Opening child process is expensive resource wise.
system()call will always open a child process to execute, BUT, it may either open a shell which will in turn fork off the desired program as its own child process (thus resulting in 2 child processes), or fork off the program as a child process directly.The choice of when Perl will open a shell during a
system()call is spelled out in perldoc -f system. The short (and not 100% accurate) version is:If there is only one parameter to system call, and the parameter evaluates to a string that contains shell meta-characters, a shell will be forked first.
If there’s only one parameter and it evaluates to no metacharacters; or there’s a >1 element list of parameters, the program is forked directly bypassing shell.
Thus: