Wine – Windows executable running on Linux box.

從以前就想在 Linux 上來執行 Windows 的應用程式,那時候想到的辦法是利用 Linux + VMWare,透過 VMWare 在 Linux 上再啟動一個 Windows based OS,於是就可以在這個 windows OS 來執行 Windows AP。但這種方法的缺點是資源耗用的比較多,PC 等級不強大概跑起來效率很差,像現在 Broso Linux 只是一台 Pentium 3 650 等級的 PC,如果想在上面多跑一個 VMWare 就很吃力了。

最近找到了另一個解決的辦法。Wine 是一個利用 Linux 各式 libraries 來實做 Windows API 的一個套件。Wine 就有點類似一個轉譯器,將 Windows API 轉為 Linux API,使其可以在 Linux 上來執行。聽起來很神奇,但我實際安裝後,
還真的可以執行 Windows AP,效能也還不差。

下圖是利用 Wine 在 Linux 上執行 NeatImage Pro 處理照片的畫面。
NeatImage Pro

有些人還利用 Wine 在 Linux 上來玩 魔獸世界 這套遊戲,看起來 Wine Windows API 轉譯的相當的好,才會連 Game 都可以執行。
原文刊載於此

魔獸世界

想在 Linux 執行 Windows AP 的話,VMWare 是要付費的軟體,但 Wine 卻完全是 Open Source,無須付費,支援程度也夠,有興趣的人真的可以試試!!

台鐵自動訂票程式

一個將程式應用在生活上的好例子,利用標準 HTTP 協定來達成台鐵自動訂票的需求!!
記得以前也寫過類似的程式,去 CNN 網站狂投公投綁大選的反對票,呵呵!!
已經很久沒坐火車了,這個程式雖然沒有 GUI 介面,不過應該不難使用,推薦給大家使用!!

原文刊載處

—————————————————————-

研究了一下台鐵訂票的html, 裡面用到一個JavaScript檔

不過是用*.js的方式與html分開, 有興趣的人可以另存網頁

再打開來研究裡面的語法…

不過就我個人使用而言, 直接指定車次去訂票比較符合我的需求

所以我修改了Yoshi兄的code,並且做了一些精簡,

另外,把訂票需要的資訊(身分證字號,起站代碼,到站代碼…)與程式分開

寫在文字檔中, 當需要訂不同的票時只要修改此文字檔, 不需重新compile

第一次post程式 請指教

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
import java.net.*;
import java.io.*;
 
public class OrderTicket {
  private static String url="http://railway.hinet.net/trw/ctno11.jsp?";
  public static void add(String attribute, String value) {
    if(url.endsWith("&") || url.endsWith("?")) {
      url+= attribute + "=" + value;
    }
    else {
      url+= "&" + attribute + "=" + value;
    }
  }
  public static void order() throws IOException {
    URL website = new URL(url);
    int count=1;
    while(true) {
      System.out.println("開始第" + count + "次嚐試訂票...");
      count++;
      URLConnection connection = website.openConnection();
      BufferedReader in = new BufferedReader(
                new InputStreamReader(connection.getInputStream()));
       String line=null;
       String content="";
       
       
       while( (line=in.readLine())!=null) {
         content+=line;
         System.out.print(".");
       }
       in.close();
       if(content.indexOf("您的車票已訂到")!=-1) {
         BufferedWriter bw = new BufferedWriter(new FileWriter("result.html"));
         bw.write(content);
         bw.close();
         System.out.println("票己成功訂到,請讀取result.html檔。");
         System.exit(0);
       }
 
       else {
         System.out.println("票尚未訂到,一分鐘之後將會再次嚐試...");
         try {
           Thread.sleep(6000); //sleep 1 minute, and try it again later.
           }catch(InterruptedException e) {
             e.printStackTrace();
           }
         }
 
      }//end while
    }
    public static void main(String[] args)  throws Exception{
 
            if (args.length != 1)
            {
                 // Print message, pause, then exit
                 System.err.println ("Invalid command parameters");
                 System.in.read();
                 System.exit(0);
            }
      BufferedReader filein = new BufferedReader(new FileReader(args[0] ));
      //BufferedReader filein = new BufferedReader(new FileReader("data.txt"));
      int i=0;
      String[] value = new String[10];
      String[] attribute = {"personId",//身分證字號
                  "fromStation",//_站代碼
                  "toStation",//到站代碼
                  "getinDate",//乘車日期
                  "orderQty",//訂票張數
                  "trainNo",//車次代碼
                  "returnTicket"//是否訂來回票
                  };
      while ((value[i] = filein.readLine()) != null) {
        add(attribute[i],value[i] );
        i++;
      }
      
      System.out.println(url);
      /*
      try {
        order();
      }
      catch(IOException e) {
        System.out.println("連線失敗,請檢查你的網路連線。");
      }
      */
      
    }
}
 

編譯完 需要另外新增一個文字檔案儲存訂票資訊

執行時的第一個參數為此文字檔案檔名