java程序 bat_java执行bat文件_bat文件启动java程序_bat脚本执行java程序

c20a6a5209e5181ce7baeb4bc1789a85.JPEG

06b9a6ae08b55478191dffa87573827c.png

c55b8df667fb6c8229234ad9d32d1eef.png

chenliangfu

32cf3b357ac33d2a0f7828af8ae30808.png

import java。io。BufferedReader;import java。io。BufferedWriter;import java。io。IOException;import java。io。InputStream;import java。io。InputStreamReader;import java。io。OutputStream;import java。io。OutputStreamWriter;import java。util。LinkedList;public class Command { private java。lang。Process p; private InputStream is; private OutputStream os; private BufferedWriter bw; private BufferedReader br; private ProcessBuilder pb; private InputStream stdErr; public Command() { } //籸ocess的输入,输硃ublic void setCmd(String cmd) { try { p = Runtime。

130422140472875.jpg

getRuntime()。exec(cmd); os = p。getOutputStream(); is = p。getInputStream(); stdErr = p。getErrorStream(); } catch (IOException e) { System。err。println(e。getMessage()); } } //蟘ess输愁 public void writeCmd(String cmd) { try { bw = new BufferedWriter(new OutputStreamWriter(os)); bw。write(cmd); bw。newLine(); bw。flush(); bw。close(); } catch (Exception e) { e。printStackTrace(); } } //读砪ess执行的结果 public String readCmd() { StringBuffer sb = new StringBuffer(); br = new BufferedReader(new InputStreamReader(is)); String buffer = null; try { while ((buffer = br。

4c584d45ab208597f310d97504e7f3a7.png

readLine()) != null) { sb。append(buffer + "\n"); } System。out。println(p。waitFor()); } catch (Exception e) { e。printStackTrace(); } return sb。toString(); } //将命令一股脑塞入list中 public LinkedList doCmd(LinkedList lists) { LinkedList list = new LinkedList(); for (String s : lists) { writeCmd(s); list。add(readCmd()); } return list; } public static void main(String[] args) { Command cmd = new Command(); cmd。

setCmd("cmd"); cmd。writeCmd("copy d:\\stock。xml d:\\backStock。xml"); System。out。println(cmd。readCmd()); //LinkedList list = new LinkedList(); //list。add("dir/b"); //list = cmd。doCmd(list); // for(String s:list){ // System。out。print(s); // } }}

本文来自电脑杂谈,转载请注明本文网址:

http://www.pc-fly.com/a/jisuanjixue/article-134378-1.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值