This assignment makes use of the files contained in this zip file. This assignment is due Wednesday, February 5.
For this assignment you will write a "launcher" program that creates Windows processes.
This assignment is based on the code examples from creating-processes.zip.
Write a Java console program called Launcher.java
that prompts the user with a list of the following nine programs that come with Windows, Taskmrg.exe
, notepad.exe
, mspaint.exe
, charmap.exe
, SnippingTool.exe
, calc.exe
, msinfo32.exe
, nslookup.exe
, and cmd.exe
. Have the nine programs numbered in the list from 1 to 9. Have the user choose one of the nine programs by inputting a number between 1 and 9. Then your program should use the Java ProcessBuilder API to start up the process that the user chose. After the process has been created, output a message that states the PID of the newly created process. After your program launches the user's choice, your program should once again prompt the user with the list of available programs and let the user launch another process (but see a following paragraph for two exceptions). Your program should keep on letting the user launch processes until the user enters zero.
In the zip file there is an executable jar file called launcher_demo.jar
that you can run, by double clicking on launcher_demo.cmd
, to see how your launcher program should behave. Your version of Launcher.java
should act exactly like the demo program.
The programs nslookup.exe
and cmd.exe
are different because they are not GUI programs, they are console programs like Launcher.java
. This means that when they run, those two programs will need to share the console window with the Launcher.java
process. Mark the nslookup.exe
and cmd.exe
programs in the menu with a '*'
character in front of their number as a reminder that they are different.
In order for the launcher process to share its console with a launched process, the launcher program should call the ProcessBuilder.inheritIO() method before launching the child process. After the launcher program starts either nslookup.exe
or cmd.exe
, the launcher program should call the Process.waitFor() method to wait for the launched process to terminate (otherwise, the launcher process and launched process will fight with each other over the console window, and the fight will not end well). In other words, the launcher process blocks after it launches either the nslookup.exe
or cmd.exe
process and the launcher process waits (i.e., remains blocked) until the nslookup.exe
or cmd.exe
process terminates.
After nslookup.exe
or cmd.exe
terminates, the launcher program should use the Process.exitValue() method to look up the terminated process's exit code and output a message that states the exit value. The launcher program should also use the Process.info() method to find, and print out, how much CPU time the launched process consumed while it was running. (See the code examples in creating-processes.zip for an example of a parent process sharing the console and waiting for a child process to exit.)
The nslookup.exe
and cmd.exe
programs both have a built in "help" command. Try them. Both nslookup.exe
and cmd.exe
also have a built in "exit" command that terminates their process. The cmd exit command also allows you to set cmd's exit value. (A Java program sets its exit value by calling the static System.exit(int) method.)
Make sure that your Launcher.java
program handles user input properly. If the user does not enter a value or the user inputs an improper value, then your program should issue another prompt (see the demo program).
Here is a list of classes and methods that you can use from the Java API.
Turn in a zip file called CS51590Hw1Surname.zip
(where Surname
is your last name) containing your version of Launcher.java
.
This assignment is due Wednesday, February 5.