Hey guys,

Recently I've been working with exec in order to execute several scripts
via Java.

The thing is that I don't clearly understand how they work as I'm trying to
perform asycnhronous tasks and the process seems to keep on blocking
without continuing the execution, so what I did in the meantime is to
create manual Java Thread classes to perform all of them, which isn't
elegant at all.

For example, I'm trying to run Icecast as a background process, and keep on
executing and instantiating more background ones, but it seems that with my
approach it keeps blocking.

    private void runIcecast() {
        File file = new File("Icecast");
        for (File s : file.listFiles()) {
            if (s.getName().equals("icecast.bat")) {
                DaemonExecutor executor = new DaemonExecutor();
                executor.setWorkingDirectory(file);
                executor.setExitValue(1);
                CommandLine commandLine = new
CommandLine(s.getAbsolutePath());

                try {
                    executor.execute(commandLine);
                    String line = "icecast -c icecast.xml";
                    commandLine = CommandLine.parse(line);
                    executor.execute(commandLine, new
DefaultExecuteResultHandler());
                } catch (ExecuteException e) {
                    e.printStackTrace();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }

What should I do so a new Thread is created whenever the command is
executed? Or should I just create normal Thread classes as I've been doing
until now?

Reply via email to