in reply to Re^6: Running perl from java
in thread Running perl from java

As long as I change "CQPerl" to "perl", your code works on my machine, happily printing out "Hello Elisheva".

I wonder if the issue is cqperl itself. This document suggests that cqperl (Clear Quest Perl by IBM/Rational Rose) is not designed to work as the standard Perl interpreter. http://www-01.ibm.com/support/docview.wss?uid=swg21265812 states that: cqperl is not a Perl interpreter of its own. It uses the $0 variable to determine which part of ClearQuest to run, but $0 is not set if called from the "shebang" line [ of a script. ]. I wonder if cqperl even knows what where to send the argument to "-e"? Is this a valid option letter for cqperl? The article goes on to say that you need to explicitly call "ratlperl" not "cqperl" in your shebang line. It also seems to assume that you've included "use CQPerlExt" as the first line in the script, though I'm guessing that is only necessary if you want to interact with the Clear Quest API in your script.

What happens if you replace "cqperl" with "ratlperl" in your command args array? Do you get a different result? I wonder if your script is working because it has the right shebang line, but that cqperl -e is failing because cqperl just doesn't know what to do with the "-e" option. What does your documentation say about cqperl and ratlperl command line arguments? Perhaps it is time to look at vendor forums? or make a support call?

Replies are listed 'Best First'.
Re^8: Running perl from java
by abramia (Novice) on Jan 09, 2011 at 14:22 UTC
    Elisheva,

    If I add the "-w" option, I get the following output (which I also get if I use "ratlperl" instead of "CQperl":

    Name "main::Hello" used only once: possible typo at -e line 1.

    print() on unopened filehandle Hello at -e line 1.

    Cheers, Avi.
      yeah, .exec is eating the quotes, its a win32 java bug

      Anonymous monk seems to be spot on about this being a command line argument problem, though it extends beyond just quoting. One of the links above discusses how on MsWin platforms Java takes all of the elements of String[] args and concatinates them into a single string before passing them onto the exe file. It is then up to the exe to decide how it wants to split that single string back into arguments. See http://bugs.sun.com/view_bug.do?bug_id=4064116 (this is one of the links in a reply above, but I thought I'd make it more explicit).

      This is going to make it quite difficult to pass one liners to perl via -e. As a work around, if you are dead set on running short sequences of Perl commands without a script, you could have a script whose sole purpose was to take arguments and combine them into valid Perl code. The following script takes raw command line arguments and assumes that they are Perl tokens. Also if you continue to have problems with quote characters you can use qq{....} instead of double quote characters.

      # put shebang needed for system here, i.e. call to ratlperl use strict; use warnings; # assume each command line argument is a Perl token eval join(' ', @ARGV);

      If the above script was called "runOneLiner.pl", then you would call cqperl runOneLiner.pl  print qq{Hello World\\n}. Even if this is broken into arguments at every whitespace, it will still recombine into a valid command by the time it gets passed to eval