in reply to Running perl from java

The kind of "quotes" that are needed for various shells vary.

I personally stay away from this "perl -e" syntax for a couple of reasons:
1)if the program that the -e does is "significant", I want to give it a name, make it a "real Perl" file and put it my personal library and maybe even alias it in my shell.
2) The resulting program file is executable on multi-platforms (I work on Linux and MS Windows).

So maybe my question sounds dumb, but why do you want to do that? I haven't found a good reason yet.

I am sure that we will hear how to make it work, and I also would find it interesting. In general this shell syntax problem also boggles my mind and is platform specific. I just avoid it by making a Perl executable file.

You are correct in that perl -e "print \"Hello World\"" works from the Windows command line. But a file with: print "Hello World"; works also and is a lot more clear.

Replies are listed 'Best First'.
Re^2: Running perl from java
by abramia (Novice) on Jan 06, 2011 at 12:16 UTC
    Hi Marshall, Yes, I have committed the cardinal sin of asking: "how do I implement my solution" and not: "how do I solve my problem".

    So here is my problem:

    I have a Web application that uses JSF (JavaServer Faces). The Web application needs to display data that is located in a "ClearQuest" database. My version of ClearQuest supports only a perl API, hence the requirement to execute perl from java.

    Because it's a Web application, I would like to have all the application files bundled in the one WAR file.

    So my problem is how to display the data, obtained from "ClearQuest" using perl, in a Web application?

    Cheers, Avi.

      Because it's a Web application, I would like to have all the application files bundled in the one WAR file.

      Options:

      • Place the perl script inside the WAR file, unpack it on demand, pass the filename of the unpacked script to the perl interpreter.
      • Store the perl script as a string constant inside the Java code, write that string constant into a temp file, pass the filename of the temp file to the perl interpreter.
      • Like before, but use a pipe instead of writing to a physical file, and make the perl interpreter read either stdin or some special file representing perl's end of the pipe (e.g. /dev/fd/4).

      Alexander

      --
      Today I will gladly share my knowledge and experience, for there are no sweeter words than "I told you so". ;-)