Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??

Hello Monks

The script I am writing will be implemented on a windows device. I'm not sure if the reason why it fails on windows but works in mac is due to incompatibility of commands

Overview of the script. I have A LOT of fancy binary 'chp' files that need to be converted to txt files. The only way to convert this file is through a proprietary program

cont. The script takes an array of the directories of the files, chops them up into smaller arrays of 20. For each 20 files it forks into 20 child processes which sends the command for text conversion into system. Then it parses through the file and gets the data I want

#!/usr/bin/perl use strict; use File::Find; use Parallel::ForkManager; my @toParse; # array of chip files foreach(@toParse){ my $encryptKey = $_; #Encrypted for patients my @name = split /\//, $fileManifest{$encryptKey}; #hash contains +the directories my $id = pop(@name); # @name is an array of the directory, last el +ement is the sample ID my $perlOut = join "\/",@name; # directory for perl commands my @safeID = split / /, $id; my $safeDirect = $perlOut."/".$safeID[0]; # hipaa compliant next if($safeID[0 ] =~ /cgo/ig); #----------------------------------------------------------------- # Prepare the commands for conversion + #----------------------------------------------------------------- my $cychpCommand = $fileManifest{$encryptKey}; #directory of the c +ychp file $cychpCommand =~ s/\//\\/g; # Format the directory for windows and + for the affy program $cychpCommand = "\"".$cychpCommand."\""; my $cychpTxtOut = join "\\", @name; #CYCHP TXT OUTPUT DIRECTORY + $cychpTxtOut ="\"".$cychpTxtOut."\""; + my $affyCommand = "apt-chp-to-txt -o ".$cychpTxtOut." ".$cychpComm +and; unless(exists($cychpLog{$encryptKey})) { my $rmCom = $perlOut."/apt-chp-to-txt.log"; push @toConvert1, $affyCommand; # To send commands for conversion push @toConvert2, $rmCom; # To remove the log files $cychpLog{$encryptKey}++; $timestamp = localtime(time); open LOG, ">>".$logFileName; print LOG "$encryptKey\t$safeID[0]\t$safeDirect\t-\t-\t$timestamp +\n"; close(LOG); } } #----------------------------------------------------------------- # Begin forking #----------------------------------------------------------------- my $maxProcs = scalar(@toConvert1); my $pm = new Parallel::ForkManager($maxProcs); foreach(@toConvert1){ my $pid = $pm-> start and next; # FORK Begin system($_); # CONVERSION COMMAND $pm->finish; # End of FORK } $pm->wait_all_children; # Blocks until all children are finished foreach(@toConvert2){ unlink $_; #Delete log files made by the conversion program } foreach(@toParse){ my $txtFile = $_.".txt"; open IN, $txtFile or die "Cannot open [$txtFile]\n";   while(<IN>){ parsing happens here } }

So my question is as follows,

Is my code converting the files, and then waiting until they are all finished? If not then why not? How can I accomplish this on a windows machine. I cannot convert all files at once because the resulting files are too large. I have to convert a few, parse them, and then unlink them later. The error I'm getting is that the proprietary program cannot open the log file, I presume it's deleted because I unlink them right after the conversion takes place. The only way I think this error is occurring is that the script moves on without waiting for the forking to finish


In reply to Is my code forking the way I want it to? Forking and System Calls by pimperator

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.
  • Log In?
    Username:
    Password:

    What's my password?
    Create A New User
    Chatterbox?
    and the web crawler heard nothing...

    How do I use this? | Other CB clients
    Other Users?
    Others scrutinizing the Monastery: (9)
    As of 2019-07-24 09:32 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?
      If you were the first to set foot on the Moon, what would be your epigram?






      Results (32 votes). Check out past polls.

      Notices?