ERODD HOME
Operating Systems
CPSC 304
Earl Rodd
erodd@malone.edu Extension 8546 www.malone.edu/erodd
Shell from Program Lab
Overview
In this lab, we will write a programs which will
execute operating system commands. We will do a program in C++ and
one in Java. Programs may be written in Windows or in Linux.
C++
- Name your program cmdiii.c where iii is your initials.
- Execute some operating system command which writes to standard out
(console).
- Use cout or printf statements so that you can see that the command
runs synchronously.
- Printout the return code from the command.
- Try using a non-existant command and document what happens in
comments in your program.
Java
- Name your program cmdiii.java where iii is your initials.
- Take a shell command from the command line and execute it.
- Display the return code from the command on the console.
- Count the number of lines written by the command and display
this count.
- Count the number of lines which start with 'square' or some other
string and display this count on the console.
Document in comments in your program the command you used to
test this function.
- Try using a non-existant command and document what happens in
comments in your program.
- Try using a command which will return a non-zero return code and
document the command you used in comments in your code.
Hint: If the command has parameters (e.g. ps -ef in LINUX),
you can pass this as 1 String, not 2, to the java program by
putting it in quotes like this:
java cmdiii 'ps -ef'
Hint: The 'ps -ef' command in LINUX will return a number of lines
which start with 'square'. Windows does not have this command so you
will need to figure out a way to test your count of lines which
start with a particular String.
To Turn In
- Printouts of both programs.
- Copy both programs to the instructor drive:
Windows: copy cmdiii.c R:\ERODD\STUDENTS
copy cmdiii.java R:\ERODD\STUDENTS
Linux: cp cmdiii.c /home/square/tdrive/erodd/students
cp cmdiii.java /home/square/tdrive/erodd/students