1. 程式人生 > >dos命令調用方法

dos命令調用方法

dos 取消 edit edi box sta 倒計時 msg 表示

aauto 調用 DOS 命令

方法一、最簡單的方法,直接執行DOS命令

execute("ipconfig /all")
 //不推薦,成功返回0,否則1.


方法二、用管道  //返回執行結果文本,推薦這個,沒有黑窗口
import process;
f = process.popen("ipconfig /all" )
str=f.read(-1);//全部讀取



方法三: 
           
import process;

//參數以/c開始,表示執行DOS命令,返回ture或者fause
process.execute_wait("cmd.exe","/c ipconfig /all")

  

定時關機例子:
import win.ui;
import process.popen; //使用process.popen(cmd)不會閃黑窗
/*DSG{{*/
mainForm = win.form(text="定時關機程序";right=582;bottom=206;mode="popup")
mainForm.add(
button={cls="button";text="執行";left=42;top=154;right=211;bottom=187;z=1};
button2={cls="button";text="取消";left=310;top=158;right=481;bottom=187;z=6};
edit={cls="edit";text="0";left=164;top=62;right=235;bottom=93;align="center";edge=1;multiline=1;z=5};
edit2={cls="edit";text="0";left=294;top=60;right=369;bottom=93;align="center";edge=1;z=8};
groupbox={cls="groupbox";text="定時關機";left=25;top=10;right=555;bottom=142;edge=1;z=2};
static={cls="static";text="Static";left=74;top=78;right=164;bottom=79;transparent=1;z=3};
static2={cls="static";text="倒計時";left=69;top=64;right=171;bottom=92;font=LOGFONT(h=-18);transparent=1;z=4};
static3={cls="static";text="分";left=255;top=68;right=312;bottom=88;font=LOGFONT(h=-18);transparent=1;z=7};
static4={cls="static";text="秒";left=398;top=68;right=433;bottom=89;font=LOGFONT(h=-18);transparent=1;z=9}
)
/*}}*/

mainForm.button.oncommand = function(id,event){
    var time=mainForm.edit.text*60+mainForm.edit2.text ;
    var cmdc ="shutdown -s"+" -t "+ time ;
    //mainForm.msgbox(cmdc)
    process.popen(cmdc);
}
 
mainForm.edit.oncommand = function(id,event){
     
}
 
mainForm.button2.oncommand = function(id,event){
      
    process.popen("shutdown -a");
    mainForm.msgbox("計劃已取消")
     
}
 
mainForm.edit2.oncommand = function(id,event){
     
}
 
mainForm.show();
return win.loopMessage();

  

dos命令調用方法