Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

what's the problem with a system call

2 views
Skip to first unread message

xiaolan

unread,
May 13, 2013, 11:35:45 PM5/13/13
to Perl Beginners
Hello,

what's the disadvantage when calling a system command from Perl?
i.e, system call to "rsync" rather than using the File::Rsync module.
is it hard to control the signals between the caller process and the called system command?

Thanks.

Luca Ferrari

unread,
May 14, 2013, 2:15:07 AM5/14/13
to xiaolan, Perl Beginners
Well, usually using a module you have access to several things in a
Perl way, like for instance to the arguments to pass to the command as
an hash or an array. instead of a string. Moreover, the perl module
could have some workarounds to provide you better portability.

Luca

Brian Fraser

unread,
May 14, 2013, 2:53:07 AM5/14/13
to xiaolan, Perl Beginners
The only real disadvantage is portability, perhaps speed (e.g. PerlIO::gzip is faster than calling gzip itself, and if you're shelling out multiple times, it'll generally be slower than simply using a module).
Additionally, if you're passing user-provided arguments to the outside command and aren't doing things "properly", that is, you aren't using IPC::Cmd, IPC::Run, or multi-arg open, you have a potential security hole in your program.

But if what you're doing doesn't gain any advantages from increased portability or security, there's nothing wrong with calling a system command.

Shlomi Fish

unread,
May 14, 2013, 5:16:34 AM5/14/13
to Perl Beginners
Hi Brian,

thanks for replying well to xiaolan’s question.

Regards,

Shlomi Fish

--
-----------------------------------------------------------------
Shlomi Fish http://www.shlomifish.org/
My Public Domain Photos - http://www.flickr.com/photos/shlomif/

95% of Programmers consider 95% of the code they did not write, in the bottom
5%.

Please reply to list if it's a mailing list post - http://shlom.in/reply .

xiaolan

unread,
May 14, 2013, 6:51:51 AM5/14/13
to Shlomi Fish, Perl Beginners
Thanks all  the answers.
Shlomi long time no see :)

Have another question that, what's the difference between the system call child process and the native forked child process?
Does the child process of system call have  the problems of receiving signals from the parent?




--
To unsubscribe, e-mail: beginners-...@perl.org
For additional commands, e-mail: beginne...@perl.org
http://learn.perl.org/



Shlomi Fish

unread,
May 14, 2013, 9:27:31 AM5/14/13
to Perl Beginners
Hi xiaolan,

On Tue, 14 May 2013 18:51:51 +0800
xiaolan <practi...@gmail.com> wrote:

> Thanks all the answers.
> Shlomi long time no see :)

Yes. :-) I am available on IM:

http://www.shlomifish.org/me/contact-me/

>
> Have another question that, what's the difference between the system call
> child process and the native forked child process?
> Does the child process of system call have the problems of receiving
> signals from the parent?

What system() does (at least on UNIX-like OSes) is fork a child, call exec()
with a new process and wait for the new child to terminate (plus some other
stuff to get rid of misbehaviours). A child process can still get a signal from
every process of that user or that belongs to the user root (including the
parent process, but not exclusively).

Regards,

Shlomi Fish

>
>
>
>
> On Tue, May 14, 2013 at 5:16 PM, Shlomi Fish <shl...@shlomifish.org> wrote:
>
> > Hi Brian,
> >
> > thanks for replying well to xiaolan’s question.
> >
> > Regards,
> >
> > Shlomi Fish
> >
> > --
> > -----------------------------------------------------------------
> > Shlomi Fish http://www.shlomifish.org/
> > My Public Domain Photos - http://www.flickr.com/photos/shlomif/
> >
> > 95% of Programmers consider 95% of the code they did not write, in the
> > bottom
> > 5%.
> >
> > Please reply to list if it's a mailing list post - http://shlom.in/reply .
> >
> > --
> > To unsubscribe, e-mail: beginners-...@perl.org
> > For additional commands, e-mail: beginne...@perl.org
> > http://learn.perl.org/
> >
> >
> >



--
-----------------------------------------------------------------
Shlomi Fish http://www.shlomifish.org/
Interview with Ben Collins-Sussman - http://shlom.in/sussman

Where they have burned books, they will end in burning human beings.
http://en.wikiquote.org/wiki/Heinrich_Heine

Manuel Reimer

unread,
May 16, 2013, 11:47:41 AM5/16/13
to begi...@perl.org
Shlomi Fish wrote:
> What system() does (at least on UNIX-like OSes) is fork a child, call exec()
> with a new process and wait for the new child to terminate (plus some other
> stuff to get rid of misbehaviours).

... and if you call "system" with just one long string, then Perl opens the
system default shell between your script and the external application, you
wanted to start.

So wherever possible you should prefer to use:

system('somecommand', '--param1=somevalue', '--anotherparam');

and not:

system('somecommand --param1=somevalue --anotherparam');

The first one opens *two* processes (the shell and "somecommand") while the
second only opens one process and passes the arguments directly without any
shell in between.

Yours

Manuel

0 new messages