Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Unix Programming in Perl

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
How can I use unix commands in Perl?
For instance if i want to do a menu for different shells, so i ask for input, then
if ($choice == 1) { open /bin/bash }
if ($choice == 2) { open /bin/csh }
etc

im not sure i explained correctly but i wish someone can help

 
Code:
system "/bin/bash";
will run UNIX commands if you replace the /bin/bash with whatever you want to run. --Derek

"Fear not the storm for this is where we grow strong."
 
Just watch the manpage (`man perlfunc`). There are a few methods to run and handle external programms.
For example you can set the command in backticks (`/bin/bash`;), use the system() funktion or the exec() funktion. I'm not sure about the difference about system() and exec() but you can find it in the manpage.
 
fagga --

system() forks off a new process, runs the specified program, then returns to the calling program, which has been patiently waiting for the return. Your calling program can check return codes, look for errors, etc.

exec(), on the other hand, replaces your current process with the new program and runs it. It doesn't typically return control to your program -- usually only if the exec() call itself fails for some reason.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top