常用windows command及java调用命令行操作

常用windows command及java调用命令行操作
安装软件

1.安装ImageMagick-6.2.9-4-Q8-windows-dll.exe
set path=c:/program files/imagemagick-6.2.9q8;
2.安装iview410_setup.exe
set Path=C:/Program Files/IrfanView;
3.安装插件irfanview_plugins_410_setup.exe
4.附助iview410_setup.exe,处理特珠的eps,tif文件
4.解压缩 7z457.exe
set path=C:/Program Files/7-Zip;

//开发中常有的命令
创建目录 mkdir "f:/temp"
创建文件 copy "f:/giga-805-0002.eps"   "f:/615.eps"
解压缩 7z x  -y  "f:/testpc.zip" -o"f:/TODO/temp"
解压缩一个文件到临时目录  rar x "F:/testpc/testpc.rar" n "fait00/68751_VerresXL.eps" "F:/temp" 
解压缩 一张图片 7z x  -y  "f:/test.zip" -o"f:/temp" "test.jpg" -r
不按比例生成缩略图 convert "f:/629.eps"    -resize 68x68!  "F:/629.gif"
按比例生成缩略图 convert "f:/629.eps"    -resize 68x68  "F:/629.gif"
不按比例生成缩略图 i_view32.exe "f:/635.eps"  /resize=(68,68)    /resample /convert="F:/635.gif"
按比例生成缩略图 i_view32.exe "f:/628.eps"  /resize=(600,600)  /aspectratio  /resample /convert="F:/628.gif"
获得图片大小比例 identify -format "%wx%h"   "f:/627.jpg"
移动目录到目录 move "f:/hidden/rr/*"  "f:/FAIT/rr" 
移动文件到文件 move "f:/hidden/275.jpg"  "f:/FAIT/275.jpg"
删除目录 rd "f:/hidden/rr"
删除某个文件 del 1.txt
读取文件 more 1.txt
清除目录 rd /Q /s "f:/home/localuser/TODO/temp"
支持命令生成缩略图软件
http://www.irfanview.com
支持库http://irfanview.tuwien.ac.at/plugins/irfanview_plugins_410.zip

解压后放在C:/Program Files/IrfanView/Plugins

命令行形式
http://www.xs4all.nl/~samzen/download/iview/iv_options.txt
http://www.student.oulu.fi/~vtatila/batch_tutorial.html


备份数据库
mysqldump -u root -B simatai>"F:/test.sql"
备份网站
7z a -tzip "F:/moon-%date%.zip"  -xr!"*.jar" -xr!"*__jsp.*" -ir!"F:/WebRoot/admin/"  -ir!"F:/WebRoot/WEB-INF/"
每天备份 排除*.jar,*__jsp.*文件,包含目录F:/WebRoot/admin/,F:/WebRoot/WEB-INF/
================================================
java中对命令行的操作

 

  1. public static boolean exeCommand(String cmd, String msg) {
  2.         boolean result = true;
  3.         log.debug(cmd);
  4.         Process process = null;
  5.         try {
  6.             String[] cmdary = {"cmd""/C", cmd};
  7.             process = Runtime.getRuntime().exec(cmdary);
  8.             StreamGobbler errorGobbler = new StreamGobbler(process.getErrorStream(), "Error");
  9.             StreamGobbler outputGobbler = new StreamGobbler(process.getInputStream(), "Output");
  10.             errorGobbler.start();
  11.             outputGobbler.start();
  12.             if (errorGobbler.is.read() != -1) {
  13.                 result = false;
  14.             }
  15.             process.waitFor();
  16.         } catch (Exception e) {
  17.             log.debug("execute commond failed : " + e);
  18.             result = false;
  19.         }
  20.         if (!result) {
  21.             log.debug(msg + " failed");
  22.         }
  23.         return result;
  24. }
  25. class StreamGobbler extends Thread {
  26.     Log log = LogFactory.getLog(StreamGobbler.class);
  27.     InputStream is;
  28.     String type;
  29.     StreamGobbler(InputStream is, String type) {
  30.         this.is = is;
  31.         this.type = type;
  32.     }
  33.     public void run() {
  34.         try {
  35.             InputStreamReader isr = new InputStreamReader(is);
  36.             BufferedReader br = new BufferedReader(isr);
  37.             String line = null;
  38.             while ((line = br.readLine()) != null) {
  39.                 if (type.equals("Error"))
  40.                     log.debug(line);
  41.                 else
  42.                     log.debug(line);
  43.             }
  44.         } catch (IOException ioe) {
  45.             ioe.printStackTrace();
  46.         }
  47.     }
  48. }

================================================

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值