Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

Re^2: Calling Java using system()

by sophix (Sexton)
on Jun 24, 2011 at 20:05 UTC ( [id://911313]=note: print w/replies, xml ) Need Help??


in reply to Re: Calling Java using system()
in thread Calling Java using system()

Hi,

Thank you for your reply.

No the "java" command but the executable jar file resides in that folder.

I tried changing the directory as follows:

my $pwd = cwd(); my $newDIR ="/users/sophix/Desktop/prottest3/prottest3/"; chdir $newDIR or die "Hmm\n"; my $currdir = cwd();

Now, when I have java or java.exe, it complains: "Unrecognized option: -jar prottest-3.0.jar Could not create the Java virtual machine."

Replies are listed 'Best First'.
Re^3: Calling Java using system()
by Gulliver (Monk) on Jun 25, 2011 at 13:52 UTC
    c:\users/sophix/Desktop/prottest3/prottest3>java

    The ">" shows that you are calling java at the command line with no path specified, yet in your system call you give an absolute path, incorrectly as saberworks pointed out. You seem to have that part resolved.

    -jar prottest-3.0.jar -i alignment1.aa -t tree1.trees -o output1.out + -all -verbose -all-matrices -threads 3 -G -F -all-distributions -nca +t 4

    This works fine. Now when I want to embed this into a script to run it through many files, as follows

    my $out = system("/users/sophix/Desktop/prottest3/prottest3/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");

    In the system call there are missing spaces between filenames and command line switches. For example between "\.aa" . "-t ".

    I suggest two things to straighten this out. First, don't use concatenation here until you get it working. Then only use concatenation to split the long line to make it more readable. Embed your variables into a long string.

    Second, save the string into a variable, print it so you can see what is going to be called. Then after it looks like expected, pass this varible to the system command.

    One more thing I noticed, you don't need to backslash escape periods in a string. You aren't using these in regexes.

    my $cmd = "java -jar prottest-3.0.jar -i ${name}.aa -t ${name}.trees - +o ${name}.out -all -verbose -all-matrices -threads 3 -G -F -all-distr +ibutions -ncat 4"; print $cmd . "\n"; #system( $cmd );

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://911313]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others cooling their heels in the Monastery: (6)
As of 2024-04-25 08:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found