0

I'm trying to run this command in docker trough java, but i don't know why it only works when i execute the command in the host machine and not trough java (when execute on java it doesn't add or say nothing). i'm 99% sure problem are the ">>" of the echo but i don't know how to fix it.

    private void doCommand(){
    
    String command = "docker exec -i -t vsftpd bash -c 'echo -e \"myuser5\\nmypass\" >> /etc/vsftpd/virtual_users.txt'";

    try {
        ProcessBuilder pb = new ProcessBuilder(command);
        
        Process process = pb.start();

        InputStream inputStream = process.getInputStream();

        BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream));

        String line = null;

        while ((line = reader.readLine()) != null) {
            System.out.println(line);
        }
    }catch (Exception e){
        e.printStackTrace();
    }
    
}

1 Answer 1

0

Error has been resolved, fixed by using https://github.com/docker-java/docker-java

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

1 Comment

Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.

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.