辅导:常用windowscommand及java调用命令行操作
来源:优易学  2011-11-6 15:33:29   【优易学:中国教育考试门户网】   资料下载   IT书店
  常用windows command及java调用命令行操作
  安装软件
  1.安装ImageMagick-6.2.9-4-Q8-windows-dll.exe
  set pathc:\program files\imagemagick-6.2.9q8;
  2.安装iview410_setup.exe
  set PathC:\Program Files\IrfanView;
  3.安装插件irfanview_plugins_410_setup.exe
  4.附助iview410_setup.exe,处理特珠的eps,tif文件
  4.解压缩 7z457.exe
  set pathC:\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://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中对命令行的操作
  public static boolean exeCommand(String cmd, String msg) {
  boolean result true;
  log.debug(cmd);
  Process process null;
  try {
  String[] cmdary {"cmd", "/C", cmd};
  process Runtime.getRuntime().exec(cmdary);
  StreamGobbler errorGobbler new StreamGobbler(process.getErrorStream(), "Error");
  StreamGobbler outputGobbler new StreamGobbler(process.getInputStream(), "Output");
  errorGobbler.start();
  outputGobbler.start();
  if (errorGobbler.is.read() ! -1) {
  result false;
  }
  process.waitFor();
  } catch (Exception e) {
  log.debug("execute commond failed : " + e);
  result false;
  }
  if (!result) {
  log.debug(msg + " failed");
  }
  return result;
  }
  class StreamGobbler extends Thread {
  Log log LogFactory.getLog(StreamGobbler.class);
  InputStream is;
  String type;
  StreamGobbler(InputStream is, String type) {
  this.is is;
  this.type type;
  }
  public void run() {
  try {
  InputStreamReader isr new InputStreamReader(is);
  BufferedReader br new BufferedReader(isr);
  String line null;
  while ((line br.readLine()) ! null) {
  if (type.equals("Error"))
  log.debug(line);
  else
  log.debug(line);
  }
  } catch (IOException ioe) {
  ioe.printStackTrace();
  }
  }
  }

责任编辑:小草

文章搜索:
 相关文章
热点资讯
资讯快报
热门课程培训