469,356 Members | 1,994 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,356 developers. It's quick & easy.

How to give run time inputs to a command?

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
7 4867
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
3,503 Expert Mod 2GB
@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
4,059 Expert 2GB
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
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
3,503 Expert Mod 2GB
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
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
4,059 Expert 2GB
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.

Similar topics

11 posts views Thread by Sven Neuberg | last post: by
1 post views Thread by Don | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.