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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Perl script executing command with options and args

Status
Not open for further replies.

Panika

Technical User
Jun 24, 2012
2
CA
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!!!
 
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) {
....
}
 
CPAN: 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.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top