Q:Hi, I am trying to call nu_correct from perl:
ie.
#! /usr/bin/perl
chdir(“/mydir/”);
system(“nu_correct -iter 150 -stop 5e-05 -normalize_field
file_nu_0.mnc.gz file_nu_1.mnc”);

If I run this from the command line, ie.
opus[~]$ cd /mydir
opus[/mydir]$ nu_correct -iter 150 -stop 5e-05 -normalize_field
file_nu_0.mnc.gz file_nu_1.mnc
Then everything works fine.

If however, I do this:
opus[~]$ ./perlscript.pl
Then I always get the same error:
Cannot open .imp file: file_nu_1.imp
nu_correct: crashed while running nu_estimate_np_and_em (termination status=512)

The problem seems to be that the .imp file is getting saved to the directory I was in before I ran my perl script, and not to /mydir.

I suspect this has something to do with using chdir() in perl, and to how nu_correct is calculating what its current directory.

Any tips?
http://www.bic.mni.mcgill.ca/pipermail/minc-users/2008-June/002067.html

A:You are right that the chdir/system interaction is biting you (I think). My first suggestion is why use chdir? It typically makes things more fragile. Why not just this:

  system(“nu_correct -iter 150 -stop 5e-05 -normalize_field       $indir/file_nu_0.mnc.gz $indir/file_nu_1.mnc”);

You may also be being bitten by the .gz on the file but I dont think so. My other suggestion (which will not be causing the problem) is to use system as an array, this tends to work better with filenames with spaces in them. ie:

  system(“nu_correct”, ‘-iter’, 150,
     ‘-stop’, 5e-05,
     ‘-normalize_field’,
     “$indir/file_nu_0.mnc.gz”, “$indir/file_nu_1.mnc”) == 0 or die

“I tried but couldnt\n”;

I have also added a check for the status of the command