alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

What this is

This file is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Other links

The source code

/*
 * JcmdProcessTest.java - A Java class to test the JcmdProcess class.
 * Copyright (C) 2001 John Gellene
 * jgellene@nyc.rr.com
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with the jEdit program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 *
 */

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

/**
 * A test routine for the JcmdProcess class.
 * @author John Gellene
 * @version $Id: JcmdProcessTest.java,v 1.3 2001/09/17 21:11:33 jgellene Exp $
 * 
* The class consists solely of a main method. */ public class JcmdProcessTest { /** * The main test routine. * @param argv Command line parameters. *
* This method expects a conventional command line that will be passed as * a parameter string to the Windows executable jcmd.exe. */ public static void main(String argv[]) { System.out.println("Testing JcmdProcess class."); String cmdLine = null; JcmdProcess process = null; /* Get full command line */ if(argv.length > 0) { StringBuffer sb = new StringBuffer(argv[0]); for(int i = 1; i < argv.length; ++i) { sb.append(' ').append(argv[i]); } cmdLine = sb.toString(); System.out.println("Command line: " + cmdLine); } else { System.err.println("No command line provided."); System.exit(1); } try { process = JcmdProcess.exec(cmdLine, null); BufferedReader pInput = new BufferedReader( new InputStreamReader( process.getInputStream())); String s = pInput.readLine(); /* call sendBreak after fixed number of * lines of stdout are read */ int nRead = 0; while (s != null) { System.out.println(s); if(++nRead == 5) process.sendBreak(); s = pInput.readLine(); } } catch(IOException e) { System.err.println("I/O error: " + e.toString()); } catch(Exception e) { System.err.println("JcmdProcess error: " + e.toString()); } System.out.println("Child process exited with code " + String.valueOf(process.exitValue())); System.exit(0); } } // end JcmdProcessTest.java
... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.