-2

I just want to know answers for the following question

i want to run the shell script from java , please specify how can i embed the file within the jar so that i can execute the script file ? also i have sudo commands in my script file , how i will be executing those commands during executing jar ?

Thanks

Akshay Vijapur
  • 310
  • 4
  • 16
  • 1) No. 2) Maybe, but see #3. 3) Yes. See Google Search. --- Down-vote for lack of research, and for asking multiple questions in a single question. – Andreas Oct 12 '16 at 04:33
  • The IP address setup is a configuration element in a text file. Why on earth do you want to use java to change that?! That simply doesnt make any sense. – GhostCat Oct 12 '16 at 06:46
  • currently i am developing application which needs to send data over TCP., i need to set a static IP address for the machine so that the MCU can receive the data from the pc – Akshay Vijapur Oct 12 '16 at 10:35

1 Answers1

1

The answer for 3) should be yes in reference to this answer.

import java.io.*;
public class Test {

        public static void main(String[] args) throws Exception {
                try {
                        String target = new String("Shell script");
                        Runtime rt = Runtime.getRuntime();
                        Process proc = rt.exec(target);
                        proc.waitFor();
                        StringBuffer output = new StringBuffer();
                        BufferedReader reader = new BufferedReader(new InputStreamReader(proc.getInputStream()));
                        String line = "";                       
                        while ((line = reader.readLine())!= null) {
                                output.append(line + "\n");
                        }
                        System.out.println("### " + output);
                } catch (Throwable t) {
                        t.printStackTrace();
                }
        }
}
Community
  • 1
  • 1
Severin
  • 46
  • 11