Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re^2: How to call Linux command sequentially

by mv.ashwin@gmail.com (Novice)
on Sep 13, 2011 at 10:05 UTC ( [id://925664]=note: print w/replies, xml ) Need Help??


in reply to Re: How to call Linux command sequentially
in thread How to call Linux command sequentially

OK. Now i do not have any error messages. 1. Using first command as shown above i want to create an environment. I was able to create it from my .pl script its is perfectly fine. 2. Once the environment is created the perl script idles it will not run the next line untill i exit form the environment. 3. I want to run the commands in the environment which was created by first command. I tried using cojoined command or individually one after another. but the perl idles aftre finishing the first command it wont run the rest of the lines untill i exit from the created environment.
  • Comment on Re^2: How to call Linux command sequentially

Replies are listed 'Best First'.
Re^3: How to call Linux command sequentially
by Corion (Patriarch) on Sep 13, 2011 at 10:10 UTC

    You seem to have a different opinion on what "sequentially" means. The meaning I am aware of for "sequentially" means "one after another", which means that no two commands may be running at the same time.

    You seem to want to run two commands at the same time - first the command that sets up the environment and starts a new shell, and in that shell run another command.

    The solution of piping in the commands into that shell or the solution of retrieving the environment settings from that shell are both approaches that can help here.

      Good catch Corion.
      So what you want to do is open a shell with your tool setup script and in that shell enter your the second command. Something like the following might do it for you
      #! /usr/bin/perl use strict; my $tool_shell = '/bin/toolsetup.pl -p coi -config d4 -t all -ov /nfs/ +home/akmvx/test -n toptest'; open (my $ts , "|-" , $tool_shell) || die "Failed to open tool setup:\n\tCommand:\t$tool_shell\n\tErro +r:\t$!\n"; print $ts "touch file1\n"; print $ts "$exit_command";
      print "Good ",qw(night morning afternoon evening)[(localtime)[2]/6]," fellow monks."
        Hurraahh!!!!!!! it worked...... Thanks a bunch!!! for all the who helped me in this. I appreciate it!! :o)
        One more hiccup, i was able to execute the command in the shell which i created. But the perl lines right after the " print $ts "touch file1\n"; " is not getting executed. I know we have created a new shell here but how to come back to the perl code right after giving some command in shell i created. Its like I create the shell execute some command there if it reports error i want to log it than again create a shell execute some command & log its status. i wrote some perl to log the status but that code is not executing. Also the shell i created is getting exited without having "print $ts "$exit_command"; " in my code. Pls help :)
      Sorry if the "sequentially" word have diverted you. You are correct i want the second command to be run in the environment created by first command. Initially i will be in home dir & shell:/usr/bin/tcsh when i run the first command a envirinment will be created in "/nfs/home/akmvx/test" which was the input to first command "-ov /nfs/home/akmvx/test" same shell. There the second command should be executed. Please help.
        system ("comand1 && comand2");

        Runs for me. If you can't do this try a pipe or go to sleep

        system ("sleep 50 && touch file1");

        also run

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://925664]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2024-04-18 15:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found