The Artima Developer Community
Sponsored Link

Legacy Java Answers Forum
April 2001

Advertisement

Advertisement

This page contains an archived post to the Java Answers Forum made prior to February 25, 2002. If you wish to participate in discussions, please visit the new Artima Forums.

Message:

How run run an external program in Java

Posted by Gareth Lewis on May 02, 2001 at 10:09 AM

> I am able to run external command on linux platform, but I want to run "cd" command on linux Platform. How to run "cd" command.

> Bhushan

Try the following. Remember this sort of thing makes your applications platform specific.

// Test.java

import java.io.*;

public class Test {
public static void main(String[] args) throws IOException, InterruptedException {
Runtime arg = Runtime.getRuntime();
// arg.exec("c:/winnt/notepad.exe");
Process child = arg.exec("notepad");

// child.destroy();
child.waitFor();
System.out.println(child.exitValue());
}
}




Replies:

Sponsored Links



Google
  Web Artima.com   
Copyright © 1996-2009 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use - Advertise with Us