Capturing Output Produced by Programs Running in a Child Process Wisconsin

Learn how to capture and display the standard output and the error output produced by programs executing in a child process resulting from a call to the exec method.

Local Companies

Acumium
608 310 9700 x 522
5133 West Terrace Drive Suite 300
Madison, , WI
Electroniclaim
262-240-9700
11357 N. Port Washington Rd
Mequon, WI
R.E. Coker and Associates, Inc.
262-723-8104
108 W Court St.
Elkhorn, WI
R S InfoCon, Inc.
262-898-7456
2320 Renaissance Blvd
Sturtevant, WI
Visionary Computer Solutions
262-365-9430
PO Box 406
Grafton, WI
HarrisData
800-225-0585
13555 Bishops Court
Brookfield, WI
Xorbix Technologies Inc.
414-277-5044
759 N. Milwaukee St.
Milwaukee, WI
IFS
414-577-5191
12000 W. Park Place
Milwaukee, WI
Wireless Direct
1.866.707.8498
BOX 71101
shorewood, WI
HarrisData
262-784-9099
13555 Bishop's Court, Suite 300
Brookfield, WI

Capturing Output Produced by Programs Running in a Child Process

provided by: 
Originally published at Internet.com


Java Programming Notes # 2572 * Preface * Viewing tip * Figures * Listings * Supplementary material * General background information * Preview * Discussion and sample code * Command-line input * Capturing output in a child process * Run the program * Summary * What's next? * Resources * Complete program listings * Copyright * About the author -----------------------------------

Preface

This is the second lesson in a series of tutorial lessons designed to teach you how to write programs using the Sun Java Wireless Toolkit for CLDC. The first lesson was titled Getting Started with MIDlets and the Sun Java Wireless Toolkit for CLDC (see Resources). In that lesson I provided and explained a Java programming framework that makes it relatively east to experiment with MIDlet programming.

A side trip

In this lesson, I will take a side trip into the world of Runtime.getRuntime().exec(cmdString). I will teach you how to capture and display the standard output and the error output produced by programs executing in a child process resulting from a call to that method.

Upgrade the framework

Then I will apply that knowledge to upgrade the MIDlet development framework that I presented in the previous lesson. This will make it possible to display compile time errors when the framework is used to compile a MIDlet and will also make it possible to display information written to standard output or error output by MIDlets being tested in the Sun cell phone emulator.

Not peculiar to MIDlets

Although I am including this material in a series primarily dedicated to MIDlets, the programming techniques that I will teach you in this lesson are not peculiar to the development of MIDlets. Rather, these techniques represent a general-purpose programming capability that is useful in a wide variety of applications in which the exec method is called for the purpose of executing another program in a child process.

Another minor upgrade to the framework

While I am at it, I will also show you how to upgrade the framework program to make it responsive to command-line parameters.

Viewing tip

I recommend that you open another copy of this document in a separate browser window and use the following links to easily find and view the figures and listings while you are reading about them.

Figures

* Figure 1. User interface for the framework program. * Figure 2. Framework output for a MIDlet with a programming error. * Figure 3. Partial description of the Process class. * Figure 4. Methods of the Process class. * Figure 5. Framework output for a MIDlet that produces standard output in the cell phone emulator.

Listings

* Listing 1. Contents of a simple batch file. * Listing 2. Beginning of the class and the main method. * Listing 3. Upgraded compile method. * Listing 4. The method named getChildOutput. * Listing 5. The class named ChildDataHandler. * Listing 6. The upgraded framework program named WTKFramework02. * Listing 7. The MIDlet named LifeCycle01.

Supplementary material

I recommend that you also study the other lessons in my extensive collection of online Java tutorials. You will find a consolidated index at www.DickBaldwin.com.

General background information

Referring back to the previous lesson (see Resources), The following steps are required to produce a MIDlet and to get it running in a cell phone: 1. Design the MIDlet (similar to designing any Java program) 2. Write the program code (similar to coding any Java program) 3. Compile the code (targeted to a Java v1.4 virtual machine, a specific version of the CLDC, and a specific version of the MIDP) 4. Pre-verify the compiled code 5. Create a manifest file 6. Create a Java Archive (JAR) file 7. Create a Java Application Descriptor (JAD) file 8. Test the MIDlet in a cell phone emulator 9. Deploy the MIDlet into a cell phone

The Java framework program that I presented in the previous lesson handles items 3 through 8 in the above list with the single click of a button. As mentioned earlier, I will teach you how to upgrade the framework program so that it will capture and display the standard output and error output produced by programs executing in a child process resulting from a call to the Runtime.getRuntime().exec(cmdString) method.

I will also show you how to upgrade the framework program to make it responsive to command-line parameters.

Preview

The user interface

Referring once more to the previous lesson, Figure 1 shows the user interface for the framework.

Figure 1. User interface for the framework program.

One change will impact the user interface

One of the changes that I will make to the framework in this lesson will impact the contents of the upper right text field shown in Figure 1. This text field contains the default program name. I will make it possible to change the default program name by entering a different program name on the command line when the framework program is started.

Why make this change?

This change makes it possible to create a batch file to start the framework with a different default program name. This is a very convenient procedure for repeatedly

Author: Richard G. Baldwin

Read article at Internet.com site

Featured Local Company

Xorbix Technologies Inc.

414-277-5044
759 N. Milwaukee St.
Milwaukee, WI
http://www.xorbix.com

Regional Articles
- Capturing Output Produced by Programs Running in a Child Process Appleton WI
- Capturing Output Produced by Programs Running in a Child Process Baraboo WI
- Capturing Output Produced by Programs Running in a Child Process Beaver Dam WI
- Capturing Output Produced by Programs Running in a Child Process Beloit WI
- Capturing Output Produced by Programs Running in a Child Process Brookfield WI
- Capturing Output Produced by Programs Running in a Child Process Burlington WI
- Capturing Output Produced by Programs Running in a Child Process Cedarburg WI
- Capturing Output Produced by Programs Running in a Child Process Chippewa Falls WI
- Capturing Output Produced by Programs Running in a Child Process Cudahy WI
- Capturing Output Produced by Programs Running in a Child Process De Pere WI
- Capturing Output Produced by Programs Running in a Child Process Delavan WI
- Capturing Output Produced by Programs Running in a Child Process Eau Claire WI
- Capturing Output Produced by Programs Running in a Child Process Elkhorn WI
- Capturing Output Produced by Programs Running in a Child Process Fond Du Lac WI
- Capturing Output Produced by Programs Running in a Child Process Fort Atkinson WI
- Capturing Output Produced by Programs Running in a Child Process Franklin WI
- Capturing Output Produced by Programs Running in a Child Process Green Bay WI
- Capturing Output Produced by Programs Running in a Child Process Hartland WI
- Capturing Output Produced by Programs Running in a Child Process Janesville WI
- Capturing Output Produced by Programs Running in a Child Process Kaukauna WI
- Capturing Output Produced by Programs Running in a Child Process Kenosha WI
- Capturing Output Produced by Programs Running in a Child Process La Crosse WI
- Capturing Output Produced by Programs Running in a Child Process Lake Geneva WI
- Capturing Output Produced by Programs Running in a Child Process Manitowoc WI
- Capturing Output Produced by Programs Running in a Child Process Marinette WI
- Capturing Output Produced by Programs Running in a Child Process Marshfield WI
- Capturing Output Produced by Programs Running in a Child Process Menasha WI
- Capturing Output Produced by Programs Running in a Child Process Menomonee Falls WI
- Capturing Output Produced by Programs Running in a Child Process Menomonie WI
- Capturing Output Produced by Programs Running in a Child Process Merrill WI
- Capturing Output Produced by Programs Running in a Child Process Middleton WI
- Capturing Output Produced by Programs Running in a Child Process Milwaukee WI
- Capturing Output Produced by Programs Running in a Child Process Mosinee WI
- Capturing Output Produced by Programs Running in a Child Process Mukwonago WI
- Capturing Output Produced by Programs Running in a Child Process Muskego WI
- Capturing Output Produced by Programs Running in a Child Process Neenah WI
- Capturing Output Produced by Programs Running in a Child Process New Berlin WI
- Capturing Output Produced by Programs Running in a Child Process Oak Creek WI
- Capturing Output Produced by Programs Running in a Child Process Oconomowoc WI
- Capturing Output Produced by Programs Running in a Child Process Onalaska WI
- Capturing Output Produced by Programs Running in a Child Process Oshkosh WI
- Capturing Output Produced by Programs Running in a Child Process Pewaukee WI
- Capturing Output Produced by Programs Running in a Child Process Racine WI
- Capturing Output Produced by Programs Running in a Child Process Rhinelander WI
- Capturing Output Produced by Programs Running in a Child Process Rice Lake WI
- Capturing Output Produced by Programs Running in a Child Process River Falls WI
- Capturing Output Produced by Programs Running in a Child Process Schofield WI
- Capturing Output Produced by Programs Running in a Child Process Shawano WI
- Capturing Output Produced by Programs Running in a Child Process Sheboygan WI
- Capturing Output Produced by Programs Running in a Child Process South Milwaukee WI
- Capturing Output Produced by Programs Running in a Child Process Stevens Point WI
- Capturing Output Produced by Programs Running in a Child Process Sturgeon Bay WI
- Capturing Output Produced by Programs Running in a Child Process Sun Prairie WI
- Capturing Output Produced by Programs Running in a Child Process Superior WI
- Capturing Output Produced by Programs Running in a Child Process Thiensville WI
- Capturing Output Produced by Programs Running in a Child Process Two Rivers WI
- Capturing Output Produced by Programs Running in a Child Process Watertown WI
- Capturing Output Produced by Programs Running in a Child Process Waukesha WI
- Capturing Output Produced by Programs Running in a Child Process Waupaca WI
- Capturing Output Produced by Programs Running in a Child Process Wausau WI
- Capturing Output Produced by Programs Running in a Child Process West Bend WI
- Capturing Output Produced by Programs Running in a Child Process Whitewater WI
- Capturing Output Produced by Programs Running in a Child Process Wisconsin Rapids WI
Related Local Event
2008 Early Stage Symposium
Dates: 11/5/2008 - 11/6/2008
Location: Monona Terrace
Madison WI
View Details
Rate Article
     
Articles Insider

Rss   Delicious   Digg   Add To My Yahoo   Add To My Google   Bookmark   Search Plugin

Topics:
Advertising Engineering Home Services Retail & Consumer Services
Business Services Entertainment Industrial Goods & Services Software
Career Family Insurance Technology
Cars Financial Services Internet Telecommunications
Computer Hardware Food & Beverage Legal Transportation & Logistics
Construction Health Pets Travel
Education Home Electronics Real Estate Wedding