title: Perl: Waiting for background process to finish
body: <p>My problem is that when I run the following it will say that the bash script has finishes successfully. But it doesnt wait for the script to finish, if it quits to early it will move a file that it needs. So what am I doing wrong that it wont wait for the background process to finish to move the files?</p>
  
  <pre><code>my $pid = fork();
      if($pid == -1){
       die;
      } elsif ($pid == 0){
       #system(@autoDeploy) or die;
       logit("Running auto deploy for $bundleApp");
       exec("./deployer -d $domain.$enviro -e $enviro &gt;&gt; /tmp/$domain.$enviro &amp;") 
                      or logit("Couldnt run the script.");
      }
      while (wait () != -1){
  
      }
      logit("Ran autoDeploy");
  
      logit("Moving $bundleApp, to $bundleDir/old/$bundleApp.$date.bundle");
      move("$bundleDir/$bundleApp", "$bundleDir/old/$bundleApp.$date.bundle");
      delete $curBundles{$bundleApp};
  </code></pre>