http://qs321.pair.com?node_id=925656


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

OK there was syntax problem i was able to run the command. But here comes another problem. The first command here creates the an environment, in that environment i need to execute the second command. Here nither system nor exec will do these. Untill I manually exit from environment the second command is not running. Once i exit from environment the second executes. But i need the second command to be executed in environment which was set by first command. Is it possible to do so? Please help!!!!
  • Comment on Re^4: How to call Linux command sequentially

Replies are listed 'Best First'.
Re^5: How to call Linux command sequentially
by Corion (Patriarch) on Sep 13, 2011 at 09:25 UTC
Re^5: How to call Linux command sequentially
by graff (Chancellor) on Sep 13, 2011 at 09:33 UTC
    You could try something like:
    #!/usr/bin/perl use strict; my $shpid = open( SH, '|-', '/bin/bash' ) or die "Can't launch bash: $ +!\n"; my @command_list = ( "first_command args ...\n", "second_command args ...\n" ... ); for my $cmd ( @command_list ) { print SH $cmd; } print SH "exit\n"; waitpid( $shpid, 0 );
    If the list of commands actually includes things that change the shell environment for subsequent commands, that should work as intended.