Java呼叫Windows控制台命令

2021-05-25 23:25:38 字數 1611 閱讀 6931

方法一:

public static void main(string args)

inputstream ins = null;

string cmd = new string;

tryprocess process = runtime.getruntime().exec(cmd);

// cmd 的資訊

ins = process.getinputstream();

bufferedreader reader = new bufferedreader(new inputstreamreader(

ins));

string line = null;

while ((line = reader.readline()) != null)

// 輸出

system.out.println(line);

int exitvalue = process.waitfor();

system.out.println("返回值:" + exitvalue);

// 關閉

process.getoutputstream().close();

catch (exception e)

e.printstacktrace();

}方法二:

class streamdrainer implements runnable

private inputstream ins;

public streamdrainer(inputstream ins)

this.ins = ins;

public void run()

trybufferedreader reader = new bufferedreader(new inputstreamreader(ins));

string line = null;

while ((line = reader.readline()) != null)

system.out.println(line);

}catch (exception e)

e.printstacktrace();

public class cmd

public static void main(string args)

// string cmd = new string ;

string cmd = new string

;try

process process = runtime.getruntime().exec(cmd);

new thread(new streamdrainer(process.getinputstream())).start();

new thread(new streamdrainer(process.geterrorstream())).start();

process.getoutputstream().close();

int exitvalue = process.waitfor();

system.out.println("返回值:" + exitvalue);

catch (exception e)

e.printstacktrace();

windows控制台游標控制

分步閱讀 控制台的游標具有兩個屬性 dwsize 高度,bvisible 是否顯示。具體步驟 1.得標準輸出裝置控制代碼getstdhandle 因為游標是在標準輸出裝置上顯示 2.獲取控制台游標資訊getconsolecursorinfo 可以跳過 3.設定控制台游標資訊setconsolecur...

呼叫Windows核心命令

對程式設計師而言,有一句至理名言就是 寫得好就是寫得少!writing better is writing less 以下命令可以直接在windows的執行視窗直接執行,在delphi中你要這樣使用 winexec pchar abcd sw show 其中 abcd 代表以下命令之一 more r...

呼叫Windows系統功能

彈出對話方塊 首先呼叫windows.h這個標頭檔案 include 接下來我們呼叫 messagebox messagebox 0,你好,helloworld 0 第乙個引數設定為0,第乙個引數是依賴的視窗的編號,相當於誰彈出的視窗,0為系統彈出,第二個引數是對話方塊的內容,第三個引數是對話方塊的...