Java Execute Command
来源:互联网 发布:golang redis hmget 编辑:程序博客网 时间:2024/06/03 21:51
OverView
在编写Java应用程序的过程中,偶尔需要调用一些Windows应用程序或者是一些命令,或者是需要批量执行一些现有的应用程序,这个时候可以选择使用Java的Runtime去执行。本文将简单介绍一下如何进行使用。
Chapter 1
这一部分先简单介绍一下Java的执行方式。使用Java语句调用现有的一些命令行工具,或者是批处理文件非常的简单,使用方式有两种:
第一种是执行
Process process = Runtime.getRuntime().exec("c:/test.bat");
第二种是执行
Process process = Runtime.getRuntime().exec("cmd /C c:/test.bat");
在程序运行过程中,有时我们需要等待程序运行结束之后,才继续往下执行相应的功能,这个时候,我们可以使用以下的语句来实现:
process.waitFor();
这样Java程序便会在命令行工具或者批处理程序执行结束之后才继续执行。
Chapter 2
这一部分简单介绍常用的批处理语句的使用。批处理的语句非常的简单,就是一些常用的Dos命令而已,常见的命令如下所示:
1、echo off表示在此语句后运行的命令都不显示命令行本身
2、@与echo off非常相似,写在每个命令行的最前端,表示不显示这一行的命令行(只能影响当前行)
3、单独使用echo off,会显示echo off命令,所以常常@和echo off一起使用
4、Call会调用另外一个批处理命令,如果不用call,执行完另外一个批处理命令时,将不会返回该批处理,并不会执行后续的命令
5、pause是为了防止控制台自动关闭而看不到输出的结果
6、echo 是输出命令,echo "" > tmp.txt 会将输出的结果输出到文件中
7、rem或者::是注释用的声明
8、%[1-9]是命令传输的参数,%0表示批处理本身
Reference
有关批处理的详细说明,可以查看百度文库的资料http://wenku.baidu.com/view/c2012388d0d233d4b14e6993.html
- Java Execute Command
- How To Execute Shell Command From Java
- execute Windows powershell command or .ps1 file by java
- execute command denied to user...
- Execute history command on Linux
- Please execute the "Cleanup" command.
- asmcmd not execute cp command
- command对象的Execute方法
- could not execute batch command
- PHP Execute Command Bypass Disable_functions
- Python execute adb shell command
- please execute the cleanup command
- How to create and execute JAR file in Java – Command line Eclipse Netbeans
- [root@master java]# hadoop namenode -format DEPRECATED: Use of this script to execute hdfs command i
- How to execute system command in MSSQL
- How to execute system command in MSSQL
- How to execute system command in MSSQL
- How to execute system command in MSSQL
- Delphi2007获取对象的published方法
- android:apn相关资料
- 苏格拉底与麦穗的故事
- C# Using与Try..Finally 语句探究
- AVR M16 ADC应用设计要点(转)
- Java Execute Command
- Windows程序设计笔记
- Spring 注解
- 关于QStringRef
- 数据库表的设计基础
- Direct3D的一些小贴士
- iphone开发标签栏的使用(持续更新中)
- 常用标准库头文件include
- SHELL SCRIPT 无聊小程序(三)