in reply to wait command syntax

Backticks already wait for the child process to finish before moving on.

Replies are listed 'Best First'.
Re^2: wait command syntax
by jperlq (Acolyte) on Mar 19, 2008 at 23:47 UTC
    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.

        You forgot to use the rel2abs function.
        $0 or __FILE__
      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.

        The python script mentioned was written by someone other than myself. They use several python tricks -- which may or may-not have equivelents in perl (i am no expert in cracking open binary files)

        Below is the python code as mentioned.

        #!/usr/bin/env python import sys # sys.argv[1] import os # os.walk(home) import gzip # gzip.open(filename) import commands # commands.getoutput home = "./FFCache/" if sys.argv[1:]: home = sys.argv[1] cachedata = "../../Documents/cachedata/" #commands.getoutput('chmod -R ../../Documents') #if sys.argv[2:]: cachedata = sys.argv[2] #commands.getoutput('rm -R cachedata') #commands.getoutput('rmdir cachedata') #os.mkdir(cachedata) #print "Making directory ", cachedata, "for copying cached files.\n" for root, dirs, files in os.walk(home): for filename in files: if "_CACHE_" in filename: continue content = None try: f = gzip.open(root + filename,"rb") data = f.read() if 'PNG' in data[:10]: content = "png" elif 'GIF89a' in data[:10]: content = "gif" elif 'JFIF' in data[:10]: content = "jpeg" elif 'HTML' in data[:20]: content = "html" elif 'html' in data[:20]: content = "html" else: continue #print "Copying ",filename," -> ", cachedata + filename +" +."+ content #print data[:20] f_out = open(cachedata + filename +"."+ content, "wb") f_out.write(data) #os.chmod(f_out, 0777) except IOError: f = open(root + filename,"rb") data = f.read() if 'PNG' in data[:10]: content = "png" elif 'GIF89a' in data[:10]: content = "gif" elif 'JFIF' in data[:10]: content = "jpeg" elif 'HTML' in data[:20]: content = "html" elif 'html' in data[:20]: content = "html" else: continue #print "Copying ",filename," -> ", cachedata + filename +" +."+ content #print data[:50] f_out = open(cachedata + filename +"." + content, "wb") f_out.write(data) #os.chmod(f_out, 0777) commands.getoutput('chmod -R 777 cachedata')