imperl has asked for the wisdom of the Perl Monks concerning the following question:

Hi, Ive tried creating a Perl script, that would create mulitple XML files. These XML files have to then get executed using an application, mentioned in the last line of the script. However, if I want say 5 XMLs to be created, it does get created but the execution of these XMLs happens only one at a time, provided I press the Ctrl C each time. This gets tedious if I have to create 100 such files, it defeats the entire idea of automating it, if I have to press Ctrl C each time. After the system(@command), at the end of the loop, is there anything I can do to prevent the script from looking for a Ctrl C? Thanks, your help will be greatly appreciated.
print "Enter the number of subscribers to be created:\n"; $num=<STDIN>; chomp($num); for($i=1; $i<=$num; $i++) { $files="orange$i.xml"; open(FILE, ">$files") or die "Can't open the file: $i\n"; print FILE "<?xml version=\"1.0\"?>\n"; print FILE "<report XMLns=\"http://www.siemens.com/ssn/tango/namescape +1 \">\n"; print FILE "<installationDate>04/10/2004 11:00:01</installationDat +e> <!-- date on which installation was done -->\n"; print FILE "<installationTime></installationTime>\n"; print FILE "<userinfo>\n"; print FILE "<firstname>Mickey</firstname>\n"; print FILE "<lastname>Mouse</lastname>\n"; print FILE "<telephone>403-345-9009</telephone>\n"; $emailend="\@ssn.com"; $emailid="test$i$emailend"; print FILE "<emailaddress>$emailid</emailaddress>\n"; print FILE "</userinfo>\n"; print FILE "<modeminfo>\n"; print FILE "<name>Efficient Networks Speedstream 6300 E240</na +me>\n"; print FILE "<softwarerevision>003-1086-G06</softwarerevision>\ +n"; print FILE "<fimwareversion>004-E240-A3D</fimwareversion>\n"; print FILE "<serialnumber/>\n"; print FILE "<ipaddress>165.218.33.101</ipaddress>\n"; print FILE "<macaddress>00099999556</macaddress>\n"; print FILE "<vendoroui>0003AF</vendoroui>\n"; print FILE "<status>Up/down/training</status>\n"; print FILE "</modeminfo>\n"; print FILE "</report>\n"; @commands=("./startAutoResSubTool.sh", "$files", "180.144.127.138", "8 +191", "ACS_SUBSCR_MGR"); system(@commands); }

Replies are listed 'Best First'.
Re: Program waiting for a Ctrl C for continuation
by jpeg (Chaplain) on Jun 16, 2005 at 09:56 UTC
    It looks like the control-c is going to startAutoResSubTool.sh before it finishes and thus restarting the outer for loop again. What's that script doing? Can you alter the system call to background it?
    --
    jpg
Re: Program waiting for a Ctrl C for continuation
by aditya.singh (Acolyte) on Jun 16, 2005 at 10:57 UTC
    What happens when you press Control-C is that all programs running in the foreground in your current terminal (or virtual terminal) get the signal SIGINT sent. And if you read the perldoc on system(), it says... <QUOTE>Because "system" and backticks block "SIGINT" and "SIGQUIT", killing the program they're running doesn't actually interrupt your program. </QUOTE> So what jpeg said is right. Maybe some part of your shell script is blocking the SIGINT. Perhaps you are using over-riding the general behavious of SIGINT to do something else?
Re: Program waiting for a Ctrl C for continuation
by thundergnat (Deacon) on Jun 16, 2005 at 15:15 UTC

    Perhaps a piped open would be better than a system() command?

    If necessary, you can probably print out a "^C" to the handle to kill it. This is an example where you should definitely check the return value from close().

    open my $handle, "| @commands" or die "Can't fork. $!"; #print $handle , "\x3"; # if necessary close $handle or warn "Couldn't close $handle. $!";