Runtime#exec() from within a J2EE application - Weblogic

This is a discussion on Runtime#exec() from within a J2EE application - Weblogic ; I've got a batch processing task running on a timer as part of my J2EE application on WebLogic 8.1 and I'm experiencing problems with invoking Runtime#exec() . To be more accurate, this is what I'm trying to do: [pre] /** ...

+ Reply to Thread
Results 1 to 2 of 2

Thread: Runtime#exec() from within a J2EE application

  1. Runtime#exec() from within a J2EE application

    I've got a batch processing task running on a timer as part of my J2EE application on WebLogic 8.1 and I'm experiencing problems with invoking Runtime#exec().

    To be more accurate, this is what I'm trying to do:
    [pre]
    /**
    * Moves a file in the filesystem using native shell commands.
    * @param src The file to move.
    * @param dst The destination file.
    */
    public void move(String src, String dst) {
    Runtime runtime = Runtime.getRuntime();
    Process p = runtime.exec(new String[] { "mv", "-f", src, dst });
    }
    [/pre]

    Now, this piece of code works perfectly when run manually ("java Move foo.txt bar.txt") but when it's run within the J2EE application -- as the same user as in the manual case -- the file's won't get moved anywhere.

    I suppose it's a permission/policy issue. If that's the case, how should I edit the policy file?

    I already tried to add the following lines to weblogic.policy:
    [pre]
    grant codeBase "file:${user.domain}/myServer/.internal/-" {
    permission java.security.AllPermission;
    };
    grant codeBase "file:${user.domain}/myServer/.wlnotdelete/-" {
    permission java.security.AllPermission;
    };
    [/pre]
    ...but that didn't seem to help at all.

  2. Re: Runtime#exec() from within a J2EE application

    Ok. I managed to solve this one by myself. The solution was to read the "stdout" and "stderr" streams from the process.

    Any idea why reading the streams helped?

+ Reply to Thread