-5

Possible Duplicate:
Running Command Line in Java

Is there a way to run this command line within a Java application?

cd "C:\Program Files\myfolder\"&&"C:\Program Files\Java\jre6\bin\java.exe" -jar myjar.jar

I can run it with command but i couldnt do it within Java.

5
  • 1
    why not, use a Process p=Runtime.getRuntime().exec("$your command") Commented Aug 24, 2012 at 11:13
  • 4
    Googling the question gives you an enormous amount of examples on how to do it. Commented Aug 24, 2012 at 11:14
  • Be careful for platform-dependant commands such as this. Sometimes there is no choice, but always try to do it in a platform independent method. Commented Aug 24, 2012 at 11:14
  • I don't know how to change what to change " to? Commented Aug 24, 2012 at 11:17
  • 2
    @user1622432 If your asking how to use " within exec: Just escape it, i.e. use \". Commented Aug 24, 2012 at 11:22

1 Answer 1

1

In Java, you can use Runtime.getRuntime().exec("yourcommand") to run command line arguments.

http://docs.oracle.com/javase/7/docs/api/java/lang/Runtime.html

I would however suggest using a more portable way of referencing that than what you are currently doing.

You can also use Java 6 Compiler API if you want to load classes at runtime rather than call a java program.

http://www.javabeat.net/2007/04/the-java-6-0-compiler-api/

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.