Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Calling Java using system()

by saberworks (Curate)
on Jun 24, 2011 at 19:26 UTC ( #911304=note: print w/ replies, xml ) Need Help??


in reply to Calling Java using system()

Is the "java" command actually in /users/sophix/Desktop/prottest3/prottest3/ ? Sounds like it's not. If you are running it from that directory so you can use relative path names, you should chdir to that directory first and then do not include it as part of the command path.


Comment on Re: Calling Java using system()
Re^2: Calling Java using system()
by sophix (Sexton) on Jun 24, 2011 at 20:05 UTC
    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."

      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
Node Status?
node history
Node Type: note [id://911304]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (13)
As of 2014-07-30 17:58 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (238 votes), past polls