0

I'm currently developing a little software in Java and I'm facing a problem I'm not able to solve. In a few words, I am on ArchLinux and I need to run "makepkg" in a specific directory. Of course I tried with

Runtime.getRuntime().exec("cd foo && makepkg"); 

But I discovered that I cannot cd in directories. Someone has an idea on how to do this? Thanks anyway

1 Answer 1

2

A process executor is not a shell. It's done for launching a process. A thing that can help you is to launch the process from a specified directory.

You can create a ProcessBuilder instance and set the working directory. It is my way of doing.

    ProcessBuilder pb = new ProcessBuilder("makepkg");
    pb.directory(new File("foo"));
    final Process process = pb.start();
    // then you read the flow with process.getInputStream() for example
Sign up to request clarification or add additional context in comments.

1 Comment

Thanks! I'll try with that

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.