呼叫新的Thread 來監控 cmd 
主要目的是控管時間和失敗處理的一些方法,
以及添加失敗時從新嘗試(最多3次)。


public static int executeCommandLine(String inputFilePath, String outputFilePath,String[] cmd) 
        throws IOException, InterruptedException, TimeoutException {
    //這邊設定要執行的指令字串
    cmd = new String[]{"sudo", "gs", etc...=" + outputFilePath, inputFilePath};
    System.out.println(String.join(" ", cmd));
    //紀錄執行次數用的變數
    int count = 0;
    do
    {
        Runtime runtime = Runtime.getRuntime();
        Process process = runtime.exec(cmd);
        Worker worker = new Worker(process);
        worker.start();
        try {
            //設定等待計秒,超過 5 秒 中斷 worker
            worker.join(5000);
              count++;
            //執行成功  return worker.exit(成功下面就部會執行了)
             if (worker.exit != null){
                return worker.exit;
               }else {
                  System.out.println("cmd wait time is too long to fail");
             }
       } catch(InterruptedException ex) {
            //中斷 worker
              worker.interrupt();
             Thread.currentThread().interrupt();
             throw ex;
          } finally {
               process.destroy();
        }
    }
    //最多執行3次
    }while(count<2);        
    throw new TimeoutException();
}
    
public static class Worker extends Thread {
    private Process process;
    private Integer exit;
    private Worker(Process process) {
        this.process = process;
     }
     public void run() {
          try { 
               exit = process.waitFor();
         } catch (InterruptedException ignore) {
             return;
          }
    } 
}


 


PS.參考網址:https://stackoverflow.com/questions/808276/how-to-add-a-timeout-value-when-using-javas-runtime-exec


Joaquin(就愛睏) 發表在 痞客邦 留言(0) 人氣()

try catch 用法
try裡的敍述句有可能會丟出例外資訊 ( Exception ) ,

Joaquin(就愛睏) 發表在 痞客邦 留言(0) 人氣()

明天就是週末了,
於是我想寫個有幫助個程式出來訓練測試一下自己的能力以及腦力激盪一下,

Joaquin(就愛睏) 發表在 痞客邦 留言(0) 人氣()

首先先介紹 SELECT 這也是最常用到的功能
#select Table欄位:

Joaquin(就愛睏) 發表在 痞客邦 留言(0) 人氣()

Linux指令/usr/sbin

指令
功能說明
範例


apmd
能源管理BIOS daemon
apmd -v


atd
at 程式的deamon
atd -s


crond
ccrontab 程式的dearmon
crond


dip
手工撥號工具
dip -tv


edquota
編輯用戶或群組quota
edquota -u wzyang


httpd
Apache web server deamon
httpd -f http.conf


in.ftpd
ftp service
in.ftpd -l -a


in.telnetd
Telnet service
in.telnetd


inetd
總管所有網路service 的deamon
inetd


lpd
列印複務器
lpd


makewhatis
產生whatis 資料庫
makewhatis


mkdict
產生spell 的詞庫
mkdict


pnprobe
自動檢測系統PNP 硬體裝置
pnpprobe


pppd
ppp daemon
pppd /dev/modem 115200


pppstats
顯示ppp 裝置連線狀態
pppstats


pwconv
將/etc/passwd 使用Shadow 加密轉成/etc/shadow
pwconv


dynquotastatus
顯示quota 設置狀態
quotastatus


rdev
設置image root device
rdev -R /dev/fd0


routed
routing deamon
routed -g


sendmail
電子郵件伺服器
sendmail -bd -q30m


syslogd
記錄系統運行所有資訊的deamon
syslogd


tcpd
Internet TCP/IP 網路最重要的deamon
tcpd in.ftpd


useradd
新增系統用戶
useradd -g groupname username


userdel
刪除系統用戶
userdel username


lynx
文本流覽器
lynx

Joaquin(就愛睏) 發表在 痞客邦 留言(0) 人氣()

系統管理者指令
/sbin

指令
功能說明
範例


arp
顯示網路裝置設置與MAC address
arp


cfdisk
磁片分割工具
cfdisk


clock
設置系統時間
clock –set –data=”9/22/98 16:45:11”


depmod
設置自動載入Kernel modules
depmod -a


dumpe2fs
顯示ext2 檔系統的磁片資訊
dumpe2fs /dev/hda5


e2fsck
ext2 filesystem check
e2fsck /dev/sda1


dumpe2fs
顯示ext2 檔系統的磁片資訊
dumpe2fs /dev/hda5


e2fsck
ext2 filesystem check
e2fsck /dev/sda1


e2label
設置ext2 partition 的label name
e2label /dev/sda1 lable_name


fdisk
任何Linux Distribution 都有的磁片分割工具
fdisk /dev/hdb


halt
系統開機指令
halt -p


hdparm
查詢硬碟資訊
hdparm -i /dev/hda


ifconfig
設置網路裝置
ifconfig


init
改變系統執行runlevel
init 3


insmod
插入Kernel modules
inmod /lib/modules/2.2.113/net/tulip.o


idconfig
設置系統執行需要link 的linrary
ldconfig -v -v -v


lilo
Linux Loader
lilo -v -v -v


lsmod
顯示目前載入的Kernel Modules
lsmod


mke2fs
將partition 格式化成ext2 檔系統
mke2fs /dev/hdb2


mkinitrd
產生各版本Kernel 的initrd ramdisk
mkinitrd initrd.img 2.2.13


mkswap
格式化成swap 檔系統格式
mkswap /dev/hdb7


modprobe
自動載入Kernel 模組
modprobe -all /lib/modules/2.2.13/net/*


quotacheck
檢查系統quota 設置
quotacheck -auvg


quotaon
啟動系統quota 限制硬碟使用空間
quoton -auvg


quotaoff
關閉系統quota
quotoff -auvg


reboot
重新啟動電腦
reboot


rmmod
刪除載入的Kernel modules
rmmod module_name


runlevel
顯示目前系統執行的
runlevel


sfdisk
磁片分割工具
sfdisk /dev/hdc


shutdown
關機指令
shutdonw -r now


wapon
啟動swap
swapon -a


swapoff
關閉swap
swapoff -a

Joaquin(就愛睏) 發表在 痞客邦 留言(0) 人氣()


Linux 指令摘要
一般用戶指令/bin


 



一般用戶指令
 指令功能說明
 範例


bash 
GNU Bouren-Again Shell 
bash shell_script


cat
觀看一般文字檔案
cat file.txt


chgrp
更改群組
chgrp groupname file


chmod
更改文件許可權
chmod 755 file


chown
更改文件owner
chown username file


cp
複製檔
cp file1 file2


date
顯示日期與時間
date


dd
disk dump
dd if=input of=output


df
顯示磁片使用空間
df -m


dmesg
顯示啟動資訊
dmesg | more


echo
顯示文字
echo “Hello World”


ed
最普通的Editor
ed textfile


egrep
類似grep 的字串搜索工具
egrep keyword file


grep
字串搜索工具
grep keyword file


gunzip
解壓縮.gz 工具
gunzip file.gz


gzip
壓縮檔
gzip file


hostname
顯示主機名稱
hostname


kill
刪除process
kill <PID>


ln
link file
ln -s file linkfile


ls
顯示目錄與檔
ls -l /


mail
收/發電子郵件
mail


mkdir
建立空目錄
mkdir -p /tmp/usr/who


mknod
產生硬體裝置檔
mknod /dev/dsp0c290


more
file perusal filter
more long_file


mount
掛接檔系統
mount -t iso9660 /dev/cdrom /cdrom


mv
移動文件
mv file1 file2


netstat
監看網路狀態
netstat -ns


ping
查詢遠端主機連線狀態
ping linux.ee.nctu.edu.tw


ps
顯示系統process status
ps -aux


pwd
顯示目前工作目錄
pwd


rm
刪除檔
rm -rf


rmdir
刪除目錄
rmdir -p /tmp/user


rpm
RPM pachage 管理程式
rpm -ivh xxx.i386.rpm


stty
改變或查看terminal 的顯示模式
stty -a


sh
GNU Bourne Shell
sh shell_script


su
Switch User
su root


sync
將在記憶體的資料寫回硬碟
sync;sync;sync


tar
GNU tar 檔壓縮程式
tar zcvf tar.file.gz dir_source/


tcsh
extended C-shell
tcsh shell_script


touch
改變檔時間
touch file


umount
卸下檔系統
umount /cdrom


uname
顯示OS 版本
uname -r


vi
Visual Editor
vi file


zcat
觀看.gz 壓縮檔內容
zcat textfile.gz


alias
設置別名
alias dir="ls -alF"


apropos
查詢指令用法
apropos ls


as
portable GNU assembler
as


at
工作行程排定程式
at -f job_file 執行時間


atq
查詢at 已經排定的工作
atq


atrm
刪除at 排定的工作
atrm jobnumber


bzip2
壓縮程式,壓縮檔.bz2
bzip2 file


bzless
觀看使用bzip2 壓縮的文字檔案
bzless text.bz2


cal
calendar 日曆
cal 12 1991


cc
gNU C Compiler
cc -o output_file source.c


chfn
改變用戶資料
chfn


chsh
change Shell
chsh


clear
清除螢幕畫面
clear


cmp
比較兩個文件
cmp file1 file2


compress
壓縮程式,壓縮檔.Z
compress file


corntab
比at 強大的行程排定程式
crontab -e


diff
文字檔案比較程式
diff file1 file2


dir
功能和ls 一樣
dir


du
查詢目錄檔使用空間
du -sm dir


egcs
新版的g++ 與gcc
egcs file.cpp or file.c


eject
退出光碟
eject


elm
電子郵件程式
elm


emacs
emacs 編輯器
emacs -nw


env
顯示Shell 環境變數
env


expr
計算運算式
expr 1+4


file
顯示檔類別
file filename


find
文件搜索工具
find ./-name pattern


finger
查詢本地或遠端機器用戶資訊
finger username
 


ftp
檔傳輸程式
ftp ftp.nctu.edu.tw


ftpwho
查看目前FTP 上網人數
ftpwho


head
顯示檔頭
head -20 logfile


g++
gNU C++ Compiler
g++ -o execute file.cpp


gcc
gNU C Compiler
gcc -o execute file.c


gzip
gNU zip, 壓縮檔.gz
gzip file


ispell
英文拼寫檢查程式
ispell article


joe
類似PE2 的文本編輯器
job file.txt


last
查看系統登錄記錄
lash -100


less
一頁一頁顯示文字檔案
less longfile


locale
顯示Shell 的地方化設置
locale


locate
檔搜索指令
locate keyword


lpr
將檔放進printer queue 中等候列印
lpr -Plp0 file


lpq
顯示printer queue 的內容
lpq -Plp0


lprm
刪除lpr 送出的列印工作
lprm jobnumber


make
可讓一堆程式同時編譯的工具
make


man
網上文件
man make


man2html
可將man 文件轉成html 文件
man2html /usr/man/ls.1 >ls.html


mc
Midnight commander 檔管理員
mc


ncftp
支持續傳功能的ftp 程式
ncftp ftp.nctu.edu.tw


nslookup
查詢主機DNS 名稱或IP Address
nslookup 140.113.1.1


passwd
更改用戶密碼
passwd username


pdftops
將PDF 文件轉成PS 文件
pdftops PDF-file PS-file


pdftotext
將PDF 文件轉成text 文件
pdftotext PDF-file text-file


pico
pico textfile
功能強大的電子郵件程式


pine
功能強大的電子郵件程式
pine

Joaquin(就愛睏) 發表在 痞客邦 留言(0) 人氣()

package test;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;

Joaquin(就愛睏) 發表在 痞客邦 留言(0) 人氣()

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;

Joaquin(就愛睏) 發表在 痞客邦 留言(0) 人氣()

去年七月的時候,
下定決心要轉換跑道(轉行);

Joaquin(就愛睏) 發表在 痞客邦 留言(0) 人氣()

1
Blog Stats
⚠️

成人內容提醒

本部落格內容僅限年滿十八歲者瀏覽。
若您未滿十八歲,請立即離開。

已滿十八歲者,亦請勿將內容提供給未成年人士。