1

I have been studying JNI (Java Native Interface) since last month.It is really interesting .I mean call Java functions from C and vice versa.Now I have an intention call linux command which I mentioned above like sed,awk from Java side.also I have a little bit knowledge about Sell Script in linux. please give me some hint how to do this.

GPrathap
  • 6,717
  • 7
  • 61
  • 77

2 Answers2

1

You should Runtime.exec() or ProcessBuilder depending on what you require to execute process into your local system.

This questsions could help:

Community
  • 1
  • 1
Dubas
  • 2,715
  • 1
  • 23
  • 36
1

You could use this java snippet to run a shell command:

Process process = Runtime.getRuntime().exec("echo This is a test"); //Start the process
process.waitFor(); //Wait for the process to terminate
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream())); //Get the output
mewking
  • 13
  • 3