tags:

views:

56

answers:

2

I have a perl script that I need to tweak.

The script runs and asks me the manually put in an IP address but I want to hard code in the IP address when it asks me to input it so I need to tell the script to type in the IP and then hit enter to proceed with the script.

Can somebody please tell me how to do this? I'm sure this is probably something extremely basic, but I am not much of a scripter so I'm not sure how to do this.

The script where I need to input the IP and hit enter reads as follows:

print "\nPlease enter the IP address of the node:";
chomp($nodeIP= <STDIN>);

Thanks in advance.

+5  A: 

Easiest is to replace

print "\nPlease enter the IP address of the node:";
chomp($nodeIP= <STDIN>);

with just

$nodeIp="192.168.2.1";

Well using you address of course, not that of my router.

Starting to write to your own stdin, or emulating keystrokes is hairy.

You do not need the chomp() method as that only serves to remove the Enter from the end of the line.

Peter Tillemans
A: 

Are you trying automate one script with another? If that's the case you might be better off using a tool called expect (Expect: A Tool for Automating Interactions. I've used it for some odd install scripts.

If what you are trying to do is modify a Perl script to just wait for a user prompt then I'd replace:

print "\nPlease enter the IP address of the node:";
chomp($nodeIP= <STDIN>);

With

$nodeIP = "1.2.3.4";
print "\nThe IP is $nodeIP.  If this is correct press ENTER to continue.\n";
<STDIN>

If waiting for an ENTER key press just read STDIN and throw it away.

HerbN
Sorry, I know my question looked like it was posed by a 5th grader. I'm not a perl scripter at all. However, your answer gave me enough to figure out what I needed to do which was to just use $nodeIP="xxx";. Thanks for your help.