import java.io.*;
// This appears in Core Web Programming from
// Prentice Hall Publishers, and may be freely used
// or adapted. 1997 Marty Hall, [email protected].
/** A class that eases the pain of running external
* processes from applications.
* Lets you run a program three ways:
* <OL>
* <LI><B>exec</B>: Execute the command, returning
* immediately even if the command is still
* running. This would be appropriate
* for printing a file.
* <LI><B>execWait</B>: Execute the command, but
* don't return until the command finishes.
* This would be appropriate for
* sequential commands where the first depends
* on the second having finished (e.g.
* <CODE>javac</CODE> followed by
* <CODE>java</CODE>).
* <LI><B>execPrint</B>: Execute the command and
* print the output. This would be appropriate
* for the UNIX command <CODE>ls</CODE>.
* </OL>
* Note that the PATH is not taken into account,
* so you must specify the <B>full</B> pathname to
* the command, and shell builtin commands
* will not work. For instance, on Unix the above
* three examples might look like:
* <OL>
* <LI><PRE>Exec.exec("/usr/ucb/lpr Some-File");</PRE>
* <LI><PRE>
* Exec.execWait("/usr/local/bin/javac Foo.java");
* Exec.execWait("/usr/local/bin/java Foo");
* </PRE>
* <LI><PRE>Exec.execPrint("/usr/bin/ls -al");</PRE>
* </OL>
*
* @author Marty Hall
* (<A HREF="mailto:[email protected]">
* [email protected]</A>)
* @version 1.0 1997
*/
public class Exec {
//----------------------------------------------------
private static boolean verbose = true;
/** Determines if the Exec class should print which
* commands are being executed, and print error
* messages if a problem is found. Default is true.
*
* @param verboseFlag true: print messages.
* false: don't.
*/
public static void setVerbose(boolean verboseFlag) {
verbose = verboseFlag;
}
/** Will Exec print status messages? */
public static boolean getVerbose() {
return(verbose);
}
//----------------------------------------------------
/** Starts a process to execute the command. Returns
* immediately, even if the new process is still
* running.
*
* @param command The <B>full</B> pathname of the
* command to be executed. No shell builtins
* (e.g. "cd") or shell meta-chars (e.g. ">")
* allowed.
* @return false if a problem is known to occur, but
* since this returns immediately, problems
* aren't usually found in time.
* Returns true otherwise.
*/
public static boolean exec(String command) {
return(exec(command, false, false));
}
//----------------------------------------------------
/** Starts a process to execute the command. Waits
* for the process to finish before returning.
*
* @param command The <B>full</B> pathname of the
* command to be executed. No shell builtins
* or shell meta-chars allowed.
* @return false if a problem is known to occur,
* either due to an exception or from the
* subprocess returning a non-zero value.
* Returns true otherwise.
*/
public static boolean execWait(String command) {
return(exec(command, false, true));
}
//----------------------------------------------------
/** Starts a process to execute the command. Prints
* all output the command gives.
*
* @param command The <B>full</B> pathname of the
* command to be executed. No shell builtins
* or shell meta-chars allowed.
* @return false if a problem is known to occur,
* either due to an exception or from the
* subprocess returning a non-zero value.
* Returns true otherwise.
*/
public static boolean execPrint(String command) {
return(exec(command, true, false));
}
//----------------------------------------------------
// This creates a Process object via
// Runtime.getRuntime.exec(). Depending on the
// flags, it may call waitFor on the process
// to avoid continuing until the process terminates,
// or open an input stream from the process to read
// the results.
private static boolean exec(String command,
boolean printResults,
boolean wait) {
if (verbose) {
printSeparator();
System.out.println("Executing '" + command + "'.");
}
try {
// Start running command, returning immediately.
Process p = Runtime.getRuntime().exec(command);
// Print the output. Since we read until
// there is no more input, this causes us
// to wait until the process is completed
if(printResults) {
BufferedInputStream buffer =
new BufferedInputStream(p.getInputStream());
DataInputStream commandResult =
new DataInputStream(buffer);
String s = null;
try {
while ((s = commandResult.readLine()) != null)
System.out.println("Output: " + s);
commandResult.close();
if (p.exitValue() != 0) {
if (verbose)
printError(command +
" -- p.exitValue() != 0");
return(false);
}
// Ignore read errors; they mean process is done
} catch (Exception e) {}
// If you don't print the results, then you
// need to call waitFor to stop until the process
// is completed
} else if (wait) {
try {
System.out.println(" ");
int returnVal = p.waitFor();
if (returnVal != 0) {
if (verbose)
printError(command);
return(false);
}
} catch (Exception e) {
if (verbose)
printError(command, e);
return(false);
}
}
} catch (Exception e) {
if (verbose)
printError(command, e);
return(false);
}
return(true);
}
//----------------------------------------------------
private static void printError(String command,
Exception e) {
System.out.println("Error doing exec(" +
command + "): " + e.getMessage());
System.out.println("Did you specify the full " +
"pathname?");
}
private static void printError(String command) {
System.out.println("Error executing '" +
command + "'.");
}
//----------------------------------------------------
private static void printSeparator() {
System.out.println
("==============================================");
}
//----------------------------------------------------
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
JPEG.rar_JPEG编解码_JPEG编解码实现_jpeg_jpeg 加密_jpeg 解码 (109个子文件)
meta_out.c 112KB
tcd.c 70KB
mj2.c 62KB
j2k.c 45KB
image_to_j2k.c 40KB
index_create.c 36KB
t1.c 35KB
frames_to_mj2.c 32KB
j2k_to_image.c 28KB
t2.c 26KB
convert.c 26KB
jpip.c 22KB
pi.c 17KB
dwt.c 16KB
mqc.c 15KB
pi.c 15KB
tcd.c 12KB
t2.c 12KB
jp2.c 12KB
mj2_to_metadata.c 10KB
mj2_convert.c 9KB
wrap_j2k_in_mj2.c 9KB
jp2.c 7KB
tgt.c 5KB
tgt.c 5KB
jpt.c 5KB
BIO.C 5KB
old_bio.c 4KB
getopt.c 4KB
getopt.c 4KB
mct.c 4KB
mj2_to_frames.c 3KB
cio.c 3KB
cio.c 3KB
bio.c 3KB
int.c 3KB
int.c 3KB
raw.c 3KB
fix.c 2KB
extract_j2k_from_mj2.c 2KB
fix.c 2KB
.cvsignore 42B
.cvsignore 42B
mj2_to_metadata_Notes.doc 35KB
mj2_to_frames.dsp 8KB
mj2_to_metadata.dsp 7KB
frames_to_mj2.dsp 7KB
image_to_j2k.dsp 7KB
j2k_to_image.dsp 7KB
MJ2_Wrapper.dsp 5KB
MJ2_Extractor.dsp 5KB
image_to_j2k.dsw 746B
j2k_to_image.dsw 547B
mj2_to_metadata.dtd 25KB
j2k.h 14KB
j2k.h 11KB
tcd.h 7KB
mj2.h 5KB
jp2.h 4KB
dwt.h 4KB
tcd.h 4KB
mqc.h 3KB
t2.h 3KB
mct.h 3KB
tgt.h 3KB
pi.h 3KB
tgt.h 3KB
cio.h 3KB
pi.h 3KB
int.h 2KB
jpt.h 2KB
bio.h 2KB
t1.h 2KB
t2.h 2KB
convert.h 2KB
cio.h 2KB
raw.h 2KB
openjpeg.h 2KB
jpip.h 2KB
int.h 2KB
jp2.h 2KB
bio.h 2KB
fix.h 2KB
fix.h 1KB
Mdc.h 536B
meta_out.h 424B
mj2_convert.h 398B
getopt.h 289B
getopt.h 289B
mj2_to_metadata.h 246B
Mdc_dec.h 183B
ImageViewer.java 6KB
PgmImage.java 2KB
MML.java 2KB
Exec.java 7KB
Makefile 3KB
Makefile 2KB
Makefile 2KB
Makefile 530B
image_to_j2k.ncb 529KB
共 109 条
- 1
- 2
资源评论
我虽横行却不霸道
- 粉丝: 75
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- Python 程序语言设计模式思路-行为型模式:职责链模式:将请求从一个处理者传递到下一个处理者
- 9241703124789646.16健身系统2.apk
- postgresql-16.3-1-windows-x64.exe
- Python 程序语言设计模式思路-结构型模式:装饰器讲解及利用Python装饰器模式实现高效日志记录和性能测试
- 基于YOLOv5和DeepSORT的多目标跟踪仿真与记录
- Python 程序语言设计模式思路-创建型模式:原型模式:通过复制现有对象来创建新对象,面向对象编程
- 卸载软件geek卸载软件geek
- Python 程序语言设计模式思路-创建型模式:单例模式,确保一个类的唯一实例(装饰器)面向对象编程、继承
- skywalking-plugins.jar skywalking-alarm.jar
- 独栋别墅图纸D020-两层-10.00&11.00米- 施工图.dwg
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功