package process; import java.io.BufferedReader; import java.io.InputStream; import java.io.InputStreamReader; public class ProcessExecutor { public static void execute(String command)throws Exception{ Process process = Runtime.getRuntime().exec(command); // the exit value int exitValue = process.waitFor(); System.out.println("the exit value is "+exitValue); String line = null; // the output message from sub process InputStream inputStream = process.getInputStream(); BufferedReader inputStreamReader = new BufferedReader(new InputStreamReader(inputStream)); StringBuilder sbForInputStream = new StringBuilder(); while ((line = inputStreamReader.readLine()) != null) { sbForInputStream.append(line); } inputStreamReader.close(); System.out.println("below is the output message :\n"+sbForInputStream); // the output error message from sub process InputStream errInputStream = process.getErrorStream(); BufferedReader errInputStreamReader = new BufferedReader(new InputStreamReader(errInputStream)); StringBuilder sbForErrInputStream = new StringBuilder(); line = null; while ((line = errInputStreamReader.readLine()) != null) { sbForErrInputStream.append(line); } errInputStreamReader.close(); System.out.println("below is the error output message :\n"+sbForErrInputStream); } public static void main(String[] args)throws Exception { // execute("cmd /c dir c: "); execute("cmd /c del C:\\Users\\dell-pc\\Desktop\\test\\e.txt"); } }
相关推荐
功能:获取java进程pid 进程可根据该pid调用exec自杀 注意事项:不能改变PidTool.java所在的包,否则需要重行生成dll。 编译命令中 "-PidTool.dll" 改为 "-FePidTool.dll",我整漏了! 使用方法: 1.javac PidTool...
android项目之aidl跨进程调用举例Demo,开发aidl跨进程调用,主要分以下步骤: 1. 创建.aidl文件-该文件(YourInterface.aidl)定义了客户端可用的方法和数据的接口。 2. 在makefile文件中加入.aidl文件-(Eclipse...
Java调用Linux命令 调用Runtime.exec方法将产生一个本地的进程,并返回一个Process子类的实例, (注意:Runtime.getRuntime().exec(command)返回的是一个Process类的实例), 该实例可用于控制进程或取得进程的...
word编辑,文档修改,表格操作,ppt演示,通通通过javaj接口调用
akka实例 java实现tcp远程调用,一个服务端,一个客户端
利用java调用DOS命令获得系统的进程列表
解决Java新建进程问题 Java调用应用程序 可以学会如何使用Java的Runtime类的exec
使用java调用命令行的方式查杀进程,可以杀死除自己之外的java进程
③阻塞、唤醒:利用系统提供的线程类模仿进程,直接启动相关的系统调用即可使线程暂停或恢复,从而达到阻塞和唤醒的目的; 针对需求3 :通过编写P、V原语来实现进程的同步; 针对需求4:为进程管理器类编写调度函数...
java查看内存使用情况,启动新进程。sigar调用、有源码工程
本程序用Java来模拟进程调用与实现,并记录到达时间,结束时间,平均周转时间等,是以界面形式实现。
NULL 博文链接:https://cyj86.iteye.com/blog/1095213
为您提供PowerJob java任务调度框架下载,PowerJob是全新一代分布式调度与计算框架,支持CRON、API、固定频率、固定延迟等调度策略,提供工作流来编排任务解决依赖关系,使用简单,功能强大,文档齐全,能让您轻松...
编写一段程序,使用系统调用fork()创建两个子进程。当此程序运行时, 在系统中有一个父进程和两个子进程活动。 让每一个进程在屏幕上显示一个字符:父进程显示“A”; 子进程分别显示字符“b”和“c”。试观察记录...
使用系统调用fork()创建两个子进程,使用系统调用signal()让进程捕捉用alarm函数设置时钟的时间段终止时产生的信号,当捕捉到该信号后,父进程使用系统调用kill()向两个子进程发出信号,子进程捕捉到信号后...
因为java没办法直接操作进程,这是我自己用C++写的一个DLL,通过jNative(内含Jnative.jar包)调用进行一些进程的操作
压缩包分为三个部分,java工程(java的...ps 一下进程是否正常,如果错误请查看日志 然后就可以使用线下的php直接调用, 代码是从网上找到的,比较容易入门 当然也可以直接导入java目录下的java工程,直接运行服务端更简单