Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Perl: Exec Or System ?, which is best for this senerio
unimatrix
post Aug 17 2005, 08:07 AM
Post #1


Premium Member
Group Icon

Group: Members
Posts: 493
Joined: 15-August 05
Member No.: 7,873



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.

This post has been edited by microscopic^earthling: Aug 17 2005, 08:52 AM
Go to the top of the page
 
+Quote Post
yordan
post Aug 17 2005, 09:50 AM
Post #2


Way Out Of Control - You need a life :)
Group Icon

Group: [MODERATOR]
Posts: 1,980
Joined: 16-August 05
Member No.: 7,896



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... ohmy.gif
Go to the top of the page
 
+Quote Post
Digital Technic
post Nov 3 2005, 05:27 PM
Post #3


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 9
Joined: 3-November 05
Member No.: 9,422



Use backticks to capture output.

CODE

$output = `program optional_arguments_jere`;


Please note that those are backticks(on QWERTY it's right below the Escape key).

Regards, Digital Technic.
Go to the top of the page
 
+Quote Post
crtburn
post Nov 17 2005, 11:07 AM
Post #4


Newbie [ Level 1 ]
Group Icon

Group: Members
Posts: 4
Joined: 17-November 05
Member No.: 9,668



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 $!.

CODE
system("myprogram --foo $bar") == 0 or die "myprogram failed ($?): $!";
print "myprogram ran successfully.\n";
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Perl, the hacker language?(6)
  2. What Is Perl?(11)
  3. Perl Script(0)
  4. Does Anyone Know To Use Movabletype (perl)(6)
  5. Perl : Help(4)
  6. Simple Problem W/ Perl(5)
  7. Sockets And Perl(1)
  8. Best Place For Information On Perl(8)
  9. Strange Perl Behavior(4)
  10. Help Needed To Create Login Script With Perl/cgi(21)
  11. Create Easily Modifiable Html Templates For Use In Your Perl Cgis(0)
  12. Using Perl For Newsletter Subscription(1)
  13. Simple Perl Script...(1)
  14. Just Learning Perl(6)
  15. Perl Programming Language(1)
  1. Maximum Number Of Decimal Places In Perl Language(0)


 



- Lo-Fi Version Time is now: 30th August 2008 - 02:33 PM