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

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.

  • Comment on Re^3: How to call Linux command sequentially

Replies are listed 'Best First'.
Re^4: How to call Linux command sequentially
by Utilitarian (Vicar) on Sep 13, 2011 at 13:30 UTC
    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 :)
Re^4: How to call Linux command sequentially
by mv.ashwin@gmail.com (Novice) on Sep 13, 2011 at 10:26 UTC
    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

        tried this did not work, untill i exit from command1 command2 will not execute. If i use other commands like mkdir touch all works fine but for my command above which creates the environment i will go idle untill i exit from command1(which creates an environment)