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

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

P: 3
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?
Jun 28 '10 #1

✓ answered by toolic

Share this Question
Share on Google+
8 Replies

Expert Mod 100+
P: 589
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.
Jun 29 '10 #2

P: 70

Jun 29 '10 #3

Expert Mod 100+
P: 589
Instead of using the system function to execute findstr, I'd use open and grep.

Jun 29 '10 #4

Expert 100+
P: 983
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?
Jul 1 '10 #5

P: 3
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:

Expand|Select|Wrap|Line Numbers
  1. print ("\nEnter the target view ");
  2. chomp($target = <STDIN>);
  3. system("cleartool startview $target");
  5. print ("\nEnter the source view\n");
  6. chomp($source = <STDIN>);
  7. system("cleartool startview $source");
  9. print ("\nEnter VOB\n");
  10. chomp($vob = <STDIN>);
  11. system("cleartool mount \\$vob");
  13. $cwd = ("v:\\$target\\$vob");
  14. chdir ($cwd);
  16. system("cleartool findmerge . -ftag $source -print >> c:\\versions.txt");
  18. <more script> .....
Jul 1 '10 #6

Expert 100+
P: 983
How are you handling the case when the user enters an invalid value and cleartool fails?
Jul 1 '10 #7

P: 3
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.
Jul 1 '10 #8

Expert 100+
P: 983
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.
Jul 1 '10 #9

Post your reply

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