×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Log In

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!
  • Students Click Here

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

Students Click Here

Perl script executing command with options and args

Perl script executing command with options and args

Perl script executing command with options and args

(OP)
Hello!

I am not a programmer and never seen Perl. I was given a task to write perl script that executes UNIX/Windows command with options and arguments collected from stdin.

$Command=command;

while input_arg ne DONE
{
$commandLineSoFar= echo $Command [space] $optionWithArg
}
execute $Command $listOfOptions&args;

Options and arguments
-a argA;
-b
-c argC;
-d
-f

And $optionWithArgs will depend on what user chooses. User can choose one or more options. Not options take arguments. When user types DONE script executes command line with options and args that it collected from a user:

command -a argA -b -f


Please, help!!!

RE: Perl script executing command with options and args

You can use several modules from CPAN and get this going. Not going to be easy if you have never worked w/ Perl before.

CODE

use Getopt::Long;

GetOptions("optionName1"=>\$pointerToOptionName1,
"optionName2"=>\$pointerToOptionName2,
);
if ($pointerToOptionName1) {
....
}

RE: Perl script executing command with options and args

(OP)
Thank you for your reply!

CPAN ?

RE: Perl script executing command with options and args

CPAN: http://www.cpan.org/, You can download perl modules from here. I don't remember if Getopt::Long is a core module that comes with Perl. If not you can download and install it via CPAN.
You don't need the module to do what you have to do, but it will make it easier.

RE: Perl script executing command with options and args

Hi

Quote (max1x)

I don't remember if Getopt::Long is a core module that comes with Perl.
No need to remember. Just look at the list of Core modules (G) and if lists Getopt::Long, then it is.

Feherke.
http://feherke.github.com/

Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members! Already a Member? Login

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close