常用windowscommand及java調(diào)用命令行操作

字號:

常用windows command及java調(diào)用命令行操作
    安裝軟件
    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;
    //開發(fā)中常有的命令
    創(chuàng)建目錄 mkdir "f:\temp"
    創(chuàng)建文件 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
    備份數(shù)據(jù)庫
    mysqldump -u root -B simatai>"F:\test.sql"
    備份網(wǎng)站
    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();
    }
    }
    }