How to give run time inputs to a command?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • nirsamp
    New Member
    • Sep 2008
    • 6

    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?
  • nirsamp
    New Member
    • Sep 2008
    • 6

    #2
    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?

    Comment

    • numberwhun
      Recognized Expert Moderator Specialist
      • May 2007
      • 3467

      #3
      Originally posted by nirsamp
      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?
      I am not an expert on it, but for that you may need to look into the Expect module in CPAN.

      Regards,

      Jeff

      Comment

      • KevinADC
        Recognized Expert Specialist
        • Jan 2007
        • 4092

        #4
        Code:
        print "Would you like to lock the code? (yes/no) ";
        my $input = <STDIN>;
        chomp $input;

        Comment

        • nirsamp
          New Member
          • Sep 2008
          • 6

          #5
          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:
          Code:
          $expr = "Would you like display milestone label (Y/N) ?";
          # get the program file in current directory
          $command ="vget -R1.0 $file";
          
          my $exp = Expect->spawn($command, @params)
                               or die "Cannot spawn $command: $!\n";
          my $exp = new Expect;
          $exp->spawn($command, @parameters)
                     or die "Cannot spawn $command: $!\n";
          
          $exp->expect($timeout,qr/$expr/i, sub { $exp->send("N\r\n"); });
          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?.
          Last edited by numberwhun; Feb 17 '09, 12:55 PM. Reason: Please use code tags!

          Comment

          • numberwhun
            Recognized Expert Moderator Specialist
            • May 2007
            • 3467

            #6
            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

            Comment

            • nirsamp
              New Member
              • Sep 2008
              • 6

              #7
              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?.

              Comment

              • KevinADC
                Recognized Expert Specialist
                • Jan 2007
                • 4092

                #8
                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

                Comment

                Working...