By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
438,374 Members | 1,939 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 438,374 IT Pros & Developers. It's quick & easy.

How to give run time inputs to a command?

P: 6
I have to run a perl program in $ prompt. The program contains the following line.
* my @varcrep_output = `vget $file`;

Here "vget $file" is a command, When this command is executed, it will require some inputs to be given at run time.

Example: Would you like to lock the code?
- For this we need to give Yes or No as input.

Is there any way to give this input automatically?
Feb 12 '09 #1
Share this Question
Share on Google+
7 Replies


P: 6
I have to run a perl program in $ prompt. The program contains the following line.
* my @varcrep_output = `vget $file`;

Here "vget $file" is a command, When this command is executed, it will require some inputs to be given at run time.

Example: Would you like to lock the code?
- For this we need to give Yes or No as input.

Is there any way to give this input automatically?
Feb 12 '09 #2

numberwhun
Expert Mod 2.5K+
P: 3,503
@nirsamp
I am not an expert on it, but for that you may need to look into the Expect module in CPAN.

Regards,

Jeff
Feb 12 '09 #3

KevinADC
Expert 2.5K+
P: 4,059
Expand|Select|Wrap|Line Numbers
  1. print "Would you like to lock the code? (yes/no) ";
  2. my $input = <STDIN>;
  3. chomp $input;
  4.  
Feb 12 '09 #4

P: 6
Hi, I want to hardcode it, say "No" everytime it prompts for an input. I tried using Expect, but i got some run time error.

Code LOC_test.pl:
Expand|Select|Wrap|Line Numbers
  1. $expr = "Would you like display milestone label (Y/N) ?";
  2. # get the program file in current directory
  3. $command ="vget -R1.0 $file";
  4.  
  5. my $exp = Expect->spawn($command, @params)
  6.                      or die "Cannot spawn $command: $!\n";
  7. my $exp = new Expect;
  8. $exp->spawn($command, @parameters)
  9.            or die "Cannot spawn $command: $!\n";
  10.  
  11. $exp->expect($timeout,qr/$expr/i, sub { $exp->send("N\r\n"); });
  12.  
Error:
expect(): Unknown pattern ref (?i-xsm:Would you like display milestone label (Y/
N) ?) at LOC_test.pl line 78

how can i solve this problem?.
Feb 17 '09 #5

numberwhun
Expert Mod 2.5K+
P: 3,503
As I mentioned when I suggested the module, I am not an expert on it. The reason I suggested it is because I know that in the Unix world, Expect is used to automate processes where there may be questions asked of the user that they want to automate. Its one of those tools that is not easy to understand or use.

My suggestion, if nobody here can help you with the Expect module is to post your question over on Perlmonks. I can almost guarantee that someone over there knows it enough to help you.

Regards,

Jeff
Feb 17 '09 #6

P: 6
Hi, Thanks for the help.

I tried to interact with the command using `echo No | vget $file` and it works fine.

@varcrep_output=`echo No | vget $file`; works fine. I have another question, if "vget $file" requires two input from the user then what could be done. Say the first promt is for "Would you like display milestone label (Y/N) ? " and we give No using `echo No | vget $file`. and the second promt is for "Would you like display task label (Y/N) ? " and i need to give 'Y' as input for this. Will it be possible?.
Feb 17 '09 #7

KevinADC
Expert 2.5K+
P: 4,059
change this line:

$expr = "Would you like display milestone label (Y/N) ?";

change to:

$expr = "Would you like display milestone label \(Y\/N\) \?";

see if that helps
Feb 17 '09 #8

Post your reply

Sign in to post your reply or Sign up for a free account.