1

I'm trying to execute the following command using Java

Process acquirInterfaces = Runtime.getRuntime().exec("dumpcap -D");

and getting error as

java.io.IOException: Cannot run program "dumpcap": java.io.IOException: error=2, No such file or directory

Linux box where im executing this command has got installed with dumpcap which is located under (/usr/local/bin)

What is the mistake im doing, please help

3 Answers 3

4

Use the following line, with exact path:

Process acquirInterfaces = Runtime.getRuntime().exec("/usr/local/bin/dumpcap -D");
Sign up to request clarification or add additional context in comments.

Comments

4

Then try

Process acquirInterfaces = Runtime.getRuntime().exec("/usr/local/bin/dumpcap -D");

And in case you have any problem with the slash, use File.separator:

Process acquirInterfaces = Runtime.getRuntime().exec(File.separator + "usr" + File.separator + "local" + File.separator + "bin" + File.separator + "dumpcap -D");

1 Comment

Why would there be any problem with the slash?
1

As noted, you need to use the full name of the executable. The reason for this is that in Unix systems, searching for commands on the path is handled by the shell, not the system call itself, so when you're running a command by using a system call, you have to specify exactly where to find the program to run.

1 Comment

Thanks Chrylis, useful info

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.