Striker has asked for the wisdom of the Perl Monks concerning the following question:

I am working on a web UI using perl CGI. I have to run a script from UI and when it finishes its execution (which takes about one hour) then rename a .png file and then I have to kill some processes. here is what I am doing for it.

system "sudo -E ./top_apps.sh stats.log > dev/null &"; $pid=`sudo -E pgrep top_apps.sh -d "," | xargs echo`; system "sudo -E ./run_test.sh > /dev/null ; mv ./img/stats.log_cpu.png + ./img/stats.log_cpu$stats_no.png ; pkill $pid &;

Now when I am doing just the following

system "sudo -E ./top_apps.sh stats.log > dev/null &"; $pid=`sudo -E pgrep top_apps.sh -d "," | xargs echo`; system "sudo -E ./run_test.sh > /dev/null &;

its working fine but when I am adding commands to rename and kill PIDs web UI is giving error that 'No data Received'. When I am running this command directly from shell its working fine all the processes are going on one after one. Please tell me what is wrong in this or if there is any other method to do tasks one after one in perl.

Replies are listed 'Best First'.
Re: Executing next system command one first one is compete
by Anonymous Monk on Mar 27, 2014 at 11:27 UTC
Re: Executing next system command one first one is compete
by kcott (Archbishop) on Mar 27, 2014 at 16:03 UTC

    G'day Striker,

    You asked a very similar question (with respect to running consecutive system commands requiring some delay between them) last week: "Running 'top' command (of linux) for few minutes and then come out of system command (of perl)".

    You received several responses but replied to none of them. Why was that? Did you try any of the suggested solutions? Were any of these useful to you? For those that weren't useful, in what way were they lacking?

    "When I am running this command directly from shell its working fine all the processes are going on one after one."

    If you can get the result you want directly from the shell, then put whatever commands you are using (from the shell) in a single shell script. Your Perl script will then just need something like:

    system 'combined_shell_commands.sh';

    I suspect there's more to this than you're telling us: possibly related to your CGI code or how you envisage users interacting with your "web UI". The guidelines in "How do I post a question effectively?" may help to improve your question such that we are better able to help you.

    -- Ken

      To be more explicit, if you want to wait for each command to finish before starting the next, don't include the "&" at the end.