Error while executing linux command using Java
NickName:sureshd Ask DateTime:2013-08-10T19:51:29

Error while executing linux command using Java

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

Copyright Notice:Content Author:「sureshd」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/18161580/error-while-executing-linux-command-using-java

Answers
Gokul Nath KP 2013-08-10T11:53:50

Use the following line, with exact path:\n\nProcess acquirInterfaces = Runtime.getRuntime().exec(\"/usr/local/bin/dumpcap -D\");\n",


Luis Sep 2013-08-10T11:52:44

Then try\n\nProcess acquirInterfaces = Runtime.getRuntime().exec(\"/usr/local/bin/dumpcap -D\");\n\n\nAnd in case you have any problem with the slash, use File.separator:\n\nProcess acquirInterfaces = Runtime.getRuntime().exec(File.separator + \"usr\" + File.separator + \"local\" + File.separator + \"bin\" + File.separator + \"dumpcap -D\");\n",


More about “Error while executing linux command using Java” related questions

Error while executing linux command using Java

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":...

Show Detail

Error executing Linux command using tcl

I have the following TCL script which executes a Linux command to format a file. exec sed -r '2,$s/(.{55} )/\1\n\t/g' $formatfileName | sed 's/ $//' > $formatfileName I get an error saying can't ...

Show Detail

getting command not found error while executing a command using subprocess in cron

While executing a command through subprocess in the linux command line it is working but while executing through cron it is raising an error command not found. Why is this happening? Code: import

Show Detail

executing the customs command on linux with process builder in java

I've been struggling for a while now with this problem and i can't seem to fix it. i have tried ProcessBuilder for executing the custom command on linux terminal but its not working Actually i h...

Show Detail

Executing a Linux command (mutt) on java shell not working properly

I have a situation where I want (need) do send a file by e-mail at the execution of a given java program. The copy commands are executed fine either on Windows and Linux, however, mutt is not working

Show Detail

Executing grep command on Linux from Java always returning null

I am executing grep command from java on a linux file. Its always returning null for the following code. Process p; String matchStr="testmatch"; String output = null; try { String command = "g...

Show Detail

getting error while executing a command line with java

i'm trying to get a list of MAC addresses of available wifi networks with java . i have found a command line that returns a perfect result netsh wlan show networks mode=Bssid | findstr "BSSID" but

Show Detail

not able to add jar in linux server while executing java class

I am executing 2 java classes which have StringUtils function. For this I have common-lang3.jar so I am giving command `javac -cp common-lang3.jar *.java` this time no error but after that j...

Show Detail

Executing linux command using python subprocess

I have a requirement where I need to extract port number from a file example.ini, this file is in linux directory. Now when I am executing below command from CLI its giving exact result which I wan...

Show Detail

Error running linux command from java

I am trying to run the below command from java code using Process process =Runtime.getRuntime().exec(command) but getting the error. Command: repo forall -c 'pwd;git status' Error:'pwd;git: -c: l...

Show Detail