0

I have written a java program named Automate.java, in which the another java program named newsmail will be executed.

The problem i face here is, Automate.java is in Desktop location(should be in desktop only always due to some requirements) and newsmail is in /home/Admin/GATE521/LN_RB this location.

What must be done before the below code, such that the command prompt automatically goes to the required folder and executes the program.

String command = "java newsmail";
Process child = Runtime.getRuntime().exec(command);
1
  • You could try putting "/home/Admin/GATE521/LN_RB" on your classpath. But I get the feeling that this whole approach is very odd and unusual. Commented Sep 16, 2010 at 19:29

2 Answers 2

5

You can use this exec() :

Process child = Runtime.getRuntime().exec(command, null, new File("/home/Admin/GATE521/LN_RB"));

Resources :

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

1 Comment

command must be the called executable and the second parameter is the list of parameters passed to your command. (@see the link)
3

Use the new ProcessBuilder class, instead of Runtime.exec().

ProcessBuilder pb = new ProcessBuilder("java", "newsmail");
pb.directory("/home/Admin/GATE521/LN_RB");
pb.start();

You can even look at pb.environment() to change environment variables if necessary.

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.