dmaranan has asked for the wisdom of the Perl Monks concerning the following question:

I still am not sure how to use system() even after reading all of the documentation. For example, lets say I need to execute a program '/home/mail/add_members'. And with that program I have three arguments 'filename' 'type of e-mai' 'mailing lists'. How do I execute that program with the system() command? What I have been doing is:

system("/home/mail/addmembers -nemail.out -wy maillist");

If this should work, please tell me, if there are some grevious errors please correct me. Thank you for your help.

Replies are listed 'Best First'.
Re: How to use system()
by mirod (Canon) on Aug 30, 2001 at 18:43 UTC

    Depending in which environment you are working the list version of system might be more secure: system( "/home/mail/addmembers", "-nemail.out", "-wy maillist"); prevents the shell to interpolate the arguments, and thus cuts down dramatically on the number of security problems that can arise if the arguments are obtained from untrusted users.

Re: How to use system()
by count0 (Friar) on Aug 30, 2001 at 18:46 UTC
    Yea, that looks just fine.

    If you're looking to catch the output of it, consider using backticks. You can also use fork(), open(), or exec() to run another process.

    Take a look at chapter 14 in 'Learning Perl' ORA (the llama) if you can get your hands on it.
Re: How to use system()
by jlongino (Parson) on Aug 30, 2001 at 19:32 UTC
    There was a similar post yesterday to which my reply is also relevant to this question about testing for errors. See Re: running programs for details.
    @a=split??,'just lose the ego and get involved!';
    for(split??,'afqtw{|~'){print $a[ord($_)-97]}
Re: How to use system()
by hillard (Acolyte) on Aug 30, 2001 at 20:44 UTC
    Back ticks have definetely worked out best in the past for me. In your case you can just use:
    my $output = `/home/mail/addmembers -nemail.out -wy maillist`;
    And call it good, with the output to STDOUT being captured in the variable $output