1

I am developing a Java application which at some point of its execution is intended to run a file containing PowerBuilder instructions.

First idea was to rewrite the whole file in Java, though may be there is a cleaner way to do so - this is about executing something from the Java app to launch PowerBuilder to execute the file's instructions.

The question comes to be whether there is some class or the like in Java to perform this task - I have gone unsuccessfully through some classes whose names suggested a possible solution, such as Runnable or Callable.

Should I start translating from PowerScript to Java?

2 Answers 2

1
public final class PowerBuilderProcessRunner {

    private PowerBuilderProcessRunner() {}

    private static class StreamHandler implements Callable<Void> {

        private BufferedReader reader;
        private OutputStream outputStream;
        private PrintWriter writer;

        public StreamHandler(InputStream inputStream, OutputStream outputStream) {
            this.reader = new BufferedReader(new InputStreamReader(inputStream));
            this.outputStream = outputStream;
            this.writer = new PrintWriter(this.outputStream);
        }

        @Override
        public Void call() throws Exception {

            String line;
            while ((line = reader.readLine()) != null) {
                writer.println("OUTPUT FROM POWERBUILDER: " + line);
                writer.flush();
                Thread.yield();
            }

            return null;
        }

    }

    // Call this method to start powerbuilder
    public static void spawnProcess(/* arguments go here */) throws Exception {

        ProcessBuilder builder = new ProcessBuilder(
                "powerbuilder.exe", // or similar
                "arg1", // taken from arguments -> must be string
                "arg2", // taken from arguments -> must be string
        );

        Process process = builder.start();

        ExecutorService threadPool = Executors.newFixedThreadPool(2);
        threadPool.submit(new StreamHandler(process.getInputStream(), System.out));
        threadPool.submit(new StreamHandler(process.getErrorStream(), System.err));

        process.waitFor();
    }
}
Sign up to request clarification or add additional context in comments.

2 Comments

Have a look at the classes ProcessBuilder and Process from the java runtime :)
Thanks a million, Lars. Looks fantastic - and lots of new stuff for me to learn :-)
1

Another alternative is to build the Powerscript code into a web service and invoke it thru a regular web service call.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.