I need help with running multiple commands within one system call.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rsm06
    New Member
    • Jun 2010
    • 3

    I need help with running multiple commands within one system call.

    Example:
    I run a perl script from my c:\
    the command I want to run is first change directory from C:\ to z:
    then in Z: I want to run the dir command and performs some more commands (example findstr) and send output to a file.
    Next I want to cd in R:\ and so same as last step.

    How can I make this happen in perl?
  • RonB
    Recognized Expert Contributor
    • Jun 2009
    • 589

    #2
    Oops, I posted my comment in the wrong thread. [post removed]

    Let me finish another post, then I'll come back and answer your question.

    Comment

    • toolic
      Recognized Expert New Member
      • Sep 2009
      • 70

      #3
      chdir

      system

      Comment

      • RonB
        Recognized Expert Contributor
        • Jun 2009
        • 589

        #4
        Instead of using the system function to execute findstr, I'd use open and grep.

        open
        grep

        Comment

        • Oralloy
          Recognized Expert Contributor
          • Jun 2010
          • 988

          #5
          Why do you need a single system call?

          One option you have is to build and execute a CMD script, if you're willing to go to that level of effort.

          Also, what's wrong with using some form of fileglobing to build your list?

          Comment

          • rsm06
            New Member
            • Jun 2010
            • 3

            #6
            Tahnks to all who replied. I used the chdir and system command to do what I wanted. Here is the script I am now succesfuly running:

            Code:
            print ("\nEnter the target view ");
            chomp($target = <STDIN>);
            system("cleartool startview $target");
            
            print ("\nEnter the source view\n");
            chomp($source = <STDIN>);
            system("cleartool startview $source");
            
            print ("\nEnter VOB\n");
            chomp($vob = <STDIN>);
            system("cleartool mount \\$vob");
            
            $cwd = ("v:\\$target\\$vob");
            chdir ($cwd);
            
            system("cleartool findmerge . -ftag $source -print >> c:\\versions.txt");
            
            <more script> .....
            Last edited by numberwhun; Jul 1 '10, 05:43 PM. Reason: Please use CODE tags!

            Comment

            • Oralloy
              Recognized Expert Contributor
              • Jun 2010
              • 988

              #7
              How are you handling the case when the user enters an invalid value and cleartool fails?

              Comment

              • rsm06
                New Member
                • Jun 2010
                • 3

                #8
                I am using the until loop to look for the 3 valid entries that require the input. Until the entires are found to be valid which is checked one at a time against an array the user cannot proceed.

                Comment

                • Oralloy
                  Recognized Expert Contributor
                  • Jun 2010
                  • 988

                  #9
                  Its just that I didn't see any error checking on the system calls. My thought was out of scope for your question, though.

                  Good luck getting it done.

                  Comment

                  Working...