ZKX's LAB

JAVA中用命令行的方式执行命令 命令行方式执行

2020-07-21知识3

JAVA中用命令行的方式执行命令 你把代码也贴出来看看,光看输出实在不知道怎么回事儿命令是执行的意思,那“命令行程序”是什么意思? 命令行一般指命令提示符,即在操作系统中,提示进行命令输入的一种工作提示符。在不同的操作系统环境下,命令提示符各不相同。命令行是在OS/2,Windows CE与Windows NT平台为基础的操作系统(包括Windows 2000,Windows XP,Windows Vista,Windows Server 2003,Windows 7等等系统)下的“MS-DOS 方式”。在windows环境下,命令行程序为cmd.exe,是一个32位的命令行程序。微软Windows系统基于Windows上的命令解释程序,类似于微软的DOS操作系统。输入一些命令,cmd.exe可以执行,比如输入shutdown-s-t 30就会在30秒后关机。方便快捷地使用Word,教你Word怎么用开始运行命令行的方式打开~!电脑 word 电脑上新建word文件,例如命名为“word技巧”~!2 。即可打开一个名字为“文档1”的word新文件~!java中如何执行命令行语句 可以使用java.lang.Process和java.lang.Runtime实现,下面展示两个例子,其它用法请查阅资料:1、执行ping命令:import java.io.BufferedReader;import java.io.IOException;import java.io.InputStreamReader;public class ProcessTest {public static void main(String[]args){BufferedReader br=null;try {String cmd=\"ping 127.0.0.1;执行dos命令并获取输出结果Process proc=Runtime.getRuntime().exec(cmd);br=new BufferedReader(new InputStreamReader(proc.getInputStream(),\"GBK\"));String line;while((line=br.readLine())。null){System.out.println(line);}proc.waitFor();} catch(IOException e){e.printStackTrace();} catch(InterruptedException e){e.printStackTrace();} finally {if(br。null){try {br.close();} catch(IOException e){e.printStackTrace();}}}}}2、打开浏览器并跳转到首页:import java.io.IOException;public class ProcessTest {public static void main(String[]args){try {String exeFullPathName=\"C:/Program Files/Internet Explorer/IEXPLORE.EXE;String message=\"www.baidu.com;String[]cmd={。

随机阅读

qrcode
访问手机版