Jump to content
xisto Community
unimatrix

Perl: Exec Or System ? which is best for this senerio

Recommended Posts

I am writing a script to add submit/add projects to a queue. I don't need a returned result other than it worked or failed. The script will execute a commandline like thisL'program -b $filename -s $start -e $end -a'all I need is for that command to be send and if it suceeds return a simple"This worked"or "This failed: here is why ___________". I am just trying to remember the difference between exec and system() for this task. I've read through the documentation and am still a little confused. It's the first time I've really used PERL in at least four years.

Edited by microscopic^earthling (see edit history)

Share this post


Link to post
Share on other sites

Read your doc carefully.On unix or Linux shell scripts, "exec" means "execute what I tell you and exit immediately after that".This means that, in Unix, all the lines after the exec instruction are ignored... :D

Share this post


Link to post
Share on other sites

Use the system() function to execute a program without saving the program's output. The return value of the system() function is the program's exit status or you could check the special $? variable which will have it as well.

 

The exit value 0 means the program exited successfully and anything else probably means there was a problem. If there was an error then it will be stored in $!.

 

system("myprogram --foo $bar") == 0 or die "myprogram failed ($?): $!";print "myprogram ran successfully.\n";

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.