Perl variables in exec or system

I am new in Perl.

I am working in simple script and the varibles are working well outside the exec or system command.
but they don't work as parameters to exec or system command.

The script is attached.
please help.

I think it's the way you are using quotes. Try this:

exec "ovownodeutil -add_exnode -group_path $group -caption $line -other $line -check_before_managed_nodes";

Dear Mark,

Thank you very much for your reply.

The code worked well and the variables are passed.

But as you made sense I add nodes to an application which are listed in a file.

After making the modificatio you have advised, the script added only the first node of the list.
Please advise.

Regards,

Hi Ahmed,

The problem is because you are using exec which does not return after executing - see exec - perldoc.perl.org . Try using system instead of exec.

Thank Mark.
When I replaced the exec with system, the script didn't sense some options of the executed command.

I got the following error:
ERROR: (NDUT9005) Option -caption missing.

although the -caption option exists.
Why the system command sense that it is missing?

Please paste the actual perl code you are running so I can have a look.

#!C:\Perl\bin
print "Prepare the \"nodes.txt\" file in drive C then press enter:";
$enter = <>;
print "\n";
if ($enter == "\r")
{
print "Enter the parent node group name: ";
$group = <>;
print "\n";
$FILE = "nodes.txt";
open(FILE,"< C:/nodes.txt");
while(<FILE>)
{
$line=$_;
system "ovownodeutil -add_exnode -group_path $group -caption $line -other $line -check_before_managed_nodes";
print "$line";
}
close(FILE)
}

Ahmed,

I think this is because $group includes a linefeed because you are entering it from the command line when you reply to "Enter the parent node group name: ". When the system command interprets the arguments you are giving it then it sees:

system "ovownodeutil -add_exnode -group_path $group<linefeed>
-caption $line -other $line -check_before_managed_nodes";

so the -caption is seperated from the call to ovownodeutil and you get a message from ovownodeutil saying it is missing -caption.

I think the way around this is to chop off the linefeed after you read $group so you need to add command chomp $group like this:

print "Enter the parent node group name: ";
$group = <>;
chomp $group;
##your code above
$group = <>;
chomp $group;#<-- chomp user input to remove the newline
##your code below