0

I've seen many examples how to run bash script, I tried several and for some reason, my script fails in some functionality.

I have a script start_update_set_up that is runned by launcher:

#!/bin/bash

DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
echo "Script directory:"$DIR
nohup bash -c $DIR/start_update_set_up > $DIR/logs/start_update_set_up.log &
echo "Laucher finish execution"

If I run launcher directly from bash - if works perfectly. But if I try to run it from Java, sleep and curl function fails. Moreover, Java waiting for some reason while my main script finish execution, that I do not want and that's why I implement launcher and that's why do I want to detach it from Java by nohup

I tried: apache executor:

executor.execute(commandLine, new DefaultExecuteResultHandler()); Where commandline is my launcher.

and runtime.

Runtime runtime = Runtime.getRuntime(); 
try { Process process = runtime.exec("./launcher"); } catch (IOException e) {
   logger.error("ExecuteException at running update script");
   e.printStackTrace(); 
}

What am I missing? How to detach bash from Java?

1 Answer 1

1

I can't test it at the moment, but I think your script should terminate with an exit statement, that may be why your java code is waiting.

As for the sleep and curl functions failure, we can't help you if you don't show them.

Sign up to request clarification or add additional context in comments.

3 Comments

Sleep works, if used Process p = Runtime.getRuntime().exec(new String[] { "bash", "-c", "./launcher" });. As for curl, if run from bash - there is output. If from Java - result is empty. Let me try some public host and I will post the result
No. No output. Example: curl http://google.com/. It is in the start_update_set_up
Forwarding to the file also does not work. File created, but is empty.

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.