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

Within a perl script, I am running a python script:

`python content2.py`

However this python script takes a while to finish. And I need to constrain my perl script to wait for this python script to finish before moving on.

I believe the command I want is wait, but I am not clear on the syntax.
Anyone have experience with a wait such as this?

Replies are listed 'Best First'.
Re: wait command syntax
by ikegami (Patriarch) on Mar 19, 2008 at 23:33 UTC
    Backticks already wait for the child process to finish before moving on.
      Thank you for that insight.

      the script called `python content2.py`

      when ran from the terminal, clobers and then creates a directory called /cachedata

      but when this script is ran inside the perl script,

      sub print_content { `python content2.py`; print header; print start_html(-title=>'Strain entry', -style=>{'src'=>'/Attempt_2.css', 'type'=>'text/css'}); start_form(-action=>'forensics.cgi?button=pushed'); print table({-'align'=>'left',-'border'=>'1', -'bordercolor'=>'CCC +CCC', -'width'=>'45%', -'cellspacing'=>'0', -'cellpadding'=>'0'}); opendir CACHE_DIR, $cache_dir or die "Cannot open $cache_dir: $!"; my $file; foreach $file (readdir CACHE_DIR) { my $current_file = $file; next if ($file =~ /^\./); $file = "peregrine.local/cgi-bin/final/$cache_dir/$file"; print Tr(td({-'bgcolor'=>'#D4E4F0'}, "<a href=http://$file>$cu +rrent_file</a>")) ."\n"; } }

      the /cachedata is indeed clobered, but the new directory is not written?
      any insight as to why?
      my first guess was that the perl script was not waiting for the python script to finish.

        This kind of problem from a CGI script yells out to pay attention to the current directory. It's often "/" instead of the directory in which the script resides. If that's the problem, adding the following will do the trick.

        use File::Spec::Functions qw( rel2abs ); use File::Basename qw( dirname ); BEGIN { chdir(dirname(rel2abs($0))); }

        Update: Oops, typed basename instead of rel2abs. Fixed.

        If you're running the python script from a perl CGI script, then it may be a permissions problem. The CGI script will run as a different user than when you run it in a terminal.

        I'm sure the python script probably does other stuff than what you mentioned, but if the directory not being made is an issue... I mean, couldn't you always just make it in Perl?

        Just my 2 cents... it's usually easier to not have to try and daisy chain different stuff together if it is possible to do it all with Tool X


        I'm a peripheral visionary... I can see into the future, but just way off to the side.