Saturday, December 17, 2011

15-A Java Program Which Makes System Calls to Execute Programs from DOS

A Java Program Which Makes System Calls to Execute Programs from DOS
The following program will call a Console or DOS program written in the Windows XP environment. To get this program to work put a program called helloworld.exe perhaps compiled in C++ in the same directory as myclass.java. Click here for a copy of a program helloword.exe made in C++ to put in the directory with the file myclass.java.
import java.io.IOException;
class myclass
{
          public static void main(String[] args) throws IOException, InterruptedException
          {
                    Process p = Runtime.getRuntime().exec("cmd /c start /MIN helloworld.exe");
                    p.waitFor();
          }
}

0 comments:

Post a Comment