is perl better?

Ralf Muschall ralf at tecont.de
Mon Mar 8 23:53:30 CET 2004


"jon c" <jon_couchman at hotmail.com> writes:

> some idoit wrote a perl script that executes a java program using the
> system command.

Calling a perl author "idiot" in the presence of a java pragram sounds
funny ;-)

> All seemed fine, except when I run I find that the character string is
> too long?

Perl's system() uses the shell only if the argument contains
characters who *require* the intervention of a shell
(e.g. metacharacters like '*'), otherwise it does something like
fork() && exec().  You can test this by writing two tiny scripts:

,----
| #!/usr/bin/perl
| system('ls');
`----

,----
| #!/usr/bin/perl
| system('ls *');
`----

and running them with "strace -f".  The first one does:

2887  fork()                            = 2888
2888  execve("/bin/ls", ["ls"], [/* 52 vars */]) = 0

The second one does:

2929  fork()                            = 2930
2930  execve("/bin/sh", ["sh", "-c", "ls *"], [/* 52 vars */]) = 0
2930  execve("/bin/ls", ["ls", "Makefile", "OOo_1.1. ...

If your system has something else instead of a real shell, limits
might be exceeded.

Ralf
-- 
GS d->? s:++>+++ a+ C++++ UL+++ UH++ P++ L++ E+++ W- N++ o-- K- w--- !O M- V-
PS+>++ PE Y+>++ PGP+ !t !5 !X !R !tv  b+++ DI+++ D?  G+ e++++ h+ r? y?



More information about the Python-list mailing list