in reply to Calling Java using system()

Hi!
As system takes an array as an argument, I would rewrite your command like this:
chdir("c:/users/sophix/Desktop/prottest3/prottest3/"); my @external_command = ( "java", "-jar prottest-3.0.jar", "-i ".$name."\.aa", "-t ".$name."\.trees", "-o ".$name."\.out" , "-all","-verbose", "-all-matrices", "-threads 3", "-G", "-F", "-all-distributions", "-ncat 4"); my $out = system(@external_command);
What exactly would you like to do with your java program?
cpan:://IPC::Run3 works on various operating systems and allows you to process standard output and error messages from your java program separately.
Note: added chdir() after reading comment by saberworks Best wishes

Replies are listed 'Best First'.
Re^2: Calling Java using system()
by sophix (Sexton) on Jun 24, 2011 at 19:57 UTC
    Hi,

    Rewriting did not work.

    The program I am using is called ProtTest - it is a Java application. http://darwin.uvigo.es/software/prottest3/prottest3.html

    I am able to run this program for a single file, but I have a huge number of files and I want to loop them processing one bye one

    So this is the snippet I wrote:

    my @ctl = glob("/users/sophix/Desktop/prottest3/prottest3/*.aa"); my ($ctltrimmed, $ctlfile, $ctlfiletrimmed); foreach my $ctlfile (@ctl) { if ($ctlfile =~ m/prottest3\/prottest3\/(\S+).aa$/) {$ctlfiletrimm +ed = $1;} my $out = system("/users/sophix/Desktop/prottest3/prottest3/java.e +xe -jar prottest-3.0.jar -i " . $ctltrimmed . "-t " . $ctltrimmed . " +\.trees" . "-o " . $ctltrimmed . "\.out" . "-all -verbose -all-matric +es -threads 3 -G -F -all-distributions -ncat 4"); }

      sophix:

      It looks like you ignored saberworks' suggestion. Your java.exe is probably not in the directory you specified. First change directories, then execute the code. Something like (untested):

      chdir("/usrs/sophix/Desktop/prottest3/prottest3"); my @ctl = glob("*.aa"); my ($ctltrimmed, $ctlfile, $ctlfiletrimmed); foreach my $ctlfile (@ctl) { if ($ctlfile =~ m/(\S+).aa$/) { $ctlfiletrimmed = $1; } my $out = system("java -jar prottest-3.0.jar -i " . $ctltrimmed . "-t " . $ctltrimmed . "\.trees" . "-o " . $ctltrimmed . "\.out" . "-all -verbose -all-matrices " . "-threads 3 -G -F -all-distributions -ncat 4"); }

      ...roboticus

      When your only tool is a hammer, all problems look like your thumb.