1

Hi is there any way to executeCommand in linux terminal via spring ? I want simple example like

ping google.com

I tried using example from here http://www.mkyong.com/java/how-to-execute-shell-command-from-java/ but I cant create object

ExecuteShellComand obj = new ExecuteShellComand();
1
  • Why can't you create it? Commented May 9, 2014 at 16:22

2 Answers 2

1

You don't really need spring for that :

Runtime.getRuntime().exec("command")

will do as well. But this is discouraged, as java runs in a sandbox, and you may not be granted the access of all commands for (obvious) security reasons.

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

Comments

0

There's a typo in the class name in that example. Java requires that public top level class names match the class name itself.

public class ExecuteShellCommand {

Comments

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.