0

I'm trying to work on a security system which needs remote debugging.So what I'm searching is a way to execute a code which is in a String,like the example below but with java.

 try {

   String Code = "rundll32 powrprof.dll, SetSuspendState";// the code we need to excecute

   Runtime.getRuntime().exec(Code);


} catch (IOException e) {
}
2

2 Answers 2

1
    String Code = "rundll32 powrprof.dll, SetSuspendState";

    StringBuffer output = new StringBuffer();

    Process p;
    try {
        p = Runtime.getRuntime().exec(Code);
        p.waitFor();
        BufferedReader reader = 
                        new BufferedReader(new InputStreamReader(p.getInputStream()));

                    String line = "";           
        while ((line = reader.readLine())!= null) {
            output.append(line + "\n");
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

    System.out.println(output.toString());

Please refer the following URL for further information http://www.mkyong.com/java/how-to-execute-shell-command-from-java/

Sign up to request clarification or add additional context in comments.

Comments

0

No friend you got it wrong.I really don't want to execute cmd codes.what i really want is to execute java commands.as a string which is passed as shown below.

example :

String code = "System.out.println("Test code")";

Runtime.getRuntime().exec(Code);

something like this.

1 Comment

The example in your question states otherwise. I would adapt your original question to tell the truth then.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.