Capturing Output Produced by Programs Running in a Child Process Los Angeles CA

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

Moyea Software
92295612365
Hot building, ring street
LA, CA
Interneer Inc.
8005586832 x85
6101 W. Centinela Ave.
Culver City, CA
Cornerstone Concepts Inc
818-247-3909
600 W Broadway
Glendale, CA
Greene Computer Corporation
(818) 956-4961
200 S. Louise Street
Glendale, CA
Corticalx Inc Software Solutions & Technology
818-500-0881
425 E Colorado St
Glendale, CA
Alphatier Systems
818-409-8920
517 Griswold St
Glendale, CA
TimeTECH - Customizable Time and Attendance / Workforce Management Solutions
905-677-7009
7420 Airport Rd 203
Mississauga, CA
Hutchinson & Bloodgood, LLP
(818) 637-5000
101 N. Brand Blvd. #1600
Glendale, CA
Telsoft Solutions
818-545-8680
100 N Brand Blvd
Glendale, CA
Abraxas Technologies Inc
818-502-9100
450 N Brand Blvd
Glendale, CA

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

Moyea Software

92295612365
Hot building, ring street
LA, CA

Related Local Events
Automation Technology Expo West (ATX West)
Dates: 2/9/2010 - 2/11/2010
Location: Anaheim Convention Center
Anaheim, CA
View Details

SOLAR POWER - Exhibition and Conference
Dates: 10/12/2010 - 10/14/2010
Location: Los Angeles Convention & Exhibition Center
Los Angeles, CA
View Details

REAL-TIME & EMBEDDED COMPUTING CONFERENCE - LONG BEACH 2009
Dates: 10/1/2009 - 10/1/2009
Location: Marriott Long Beach
Long Beach, CA
View Details

2009 IEEE Petroleum and Chemical Industry Technical Conference (PCIC 2009)
Dates: 9/14/2009 - 9/16/2009
Location:
Anaheim, CA
View Details

Medical Design & Manufacturing - Trade
Dates: 6/9/2009 - 6/11/2009
Location: CANON COMMUNICATIONS LLC
Los Angeles, CA
View Details