全國最多中醫師線上諮詢網站-台灣中醫網
發文 回覆 瀏覽次數:1909
推到 Plurk!
推到 Facebook!

請問如何在c底下 呼叫一個.exe檔 並傳參數

 
xingru
一般會員


發表:4
回覆:3
積分:1
註冊:2004-10-05

發送簡訊給我
#1 引用回覆 回覆 發表時間:2006-08-14 15:58:31 IP:61.229.xxx.xxx 訂閱

在dos下

假設我現在要呼叫一個叫svm-train.exe的檔案

之後會傳參數給他如下 svm-train -v 5 -c 10 heart_scale

請問在c如何完成它"-v 5 -c 10 heart_scale"參數

aftcast
站務副站長


發表:81
回覆:1485
積分:1763
註冊:2002-11-21

發送簡訊給我
#2 引用回覆 回覆 發表時間:2006-08-14 17:27:40 IP:61.229.xxx.xxx 未訂閱

若是Turbo C 2.0 或以上,請使用function
int execl(char *path, char *arg0 *arg1, ..., *argn, NULL);

此fucntion非ANSI C標準。若你的c complier沒suport…問題就大一點,不過我想應該是都有。

再不然就呼叫DOS中斷服務程式(相當於windows的api):
使用服務4Ah,將父記憶體縮小以空出空間給子程序跑,再來使用4B00h服務,將子程序檔名指向ds:dx的位址,再將參數設定成PCB結構體4個位址共14bytes,然後將es:bx指向這個結構位址…

好懷念dos時代…應該很少人寫dos的程式了吧?!

------


蕭沖
--All ideas are worthless unless implemented--

C++ Builder Delphi Taiwan G+ 社群
http://bit.ly/cbtaiwan
aftcast
站務副站長


發表:81
回覆:1485
積分:1763
註冊:2002-11-21

發送簡訊給我
#3 引用回覆 回覆 發表時間:2006-08-14 17:33:03 IP:61.229.xxx.xxx 未訂閱
回完後覺得怪怪的。題目問的是否和我想的是一樣的?? 常覺得會誤解寫的不夠詳細的題目 -_-|||

有點又覺得像是問: 如何在c裡讀取參數? 因為…不知為何你只關心參數的部份? 難道不用傳參數時,你就知道該怎麼呼叫子程序?

有點亂了)%^$p^

sorry
------


蕭沖
--All ideas are worthless unless implemented--

C++ Builder Delphi Taiwan G+ 社群
http://bit.ly/cbtaiwan
xingru
一般會員


發表:4
回覆:3
積分:1
註冊:2004-10-05

發送簡訊給我
#4 引用回覆 回覆 發表時間:2006-08-15 15:55:18 IP:61.229.xxx.xxx 訂閱

謝謝你的答覆^^

雖然真的不太懂你的寫法

不過還是很感謝

順便一問

請問你知道winexec的使用方式嗎?

他可以傳值?

aftcast
站務副站長


發表:81
回覆:1485
積分:1763
註冊:2002-11-21

發送簡訊給我
#5 引用回覆 回覆 發表時間:2006-08-16 08:04:18 IP:61.229.xxx.xxx 未訂閱
謝謝你的回應,我想,你之間指的dos應該不是以前還沒有windows的那個時代的dos,而是指在windows下的dos box,二者是有差別的! (我就在想…現在應該極少人會去寫10幾年前的東西了…)

關於winexec這個function是可以傳參數的…

WinExec("C:\\myap -option para1 para2",SW_SHOWNORMAL)

以上假定你要呼叫的是myap,參數是-option para1 para2
簡單講就是winexec的第一個參數裡可以放的不只是檔名,還可以加進它的參數…

------


蕭沖
--All ideas are worthless unless implemented--

C++ Builder Delphi Taiwan G+ 社群
http://bit.ly/cbtaiwan
xingru
一般會員


發表:4
回覆:3
積分:1
註冊:2004-10-05

發送簡訊給我
#6 引用回覆 回覆 發表時間:2006-08-16 15:08:34 IP:61.229.xxx.xxx 訂閱

真的很感謝你的答覆

首先關於我指的dos 如你所說

是dos box 我不會寫dos的程式^^"

很感謝你針對ㄅwinexec() function的解釋

不過有一點小疑問再請教

第一個部份我們是以檔案位置 參數

那,後那是指輸出的格式嗎?

我可以選擇讓他讀入檔案?

小弟再次感謝您詳細的回答

aftcast
站務副站長


發表:81
回覆:1485
積分:1763
註冊:2002-11-21

發送簡訊給我
#7 引用回覆 回覆 發表時間:2006-08-17 10:47:39 IP:61.229.xxx.xxx 未訂閱

後面的參數SW_SHOWNORMAL是指你要執行的那程式在被開啟的時候是呈現怎樣的狀態,比如說我下的這個參數是指用一般的方式展現,也可以是下面的幾種,我貼msdn的給你看看,自行參考吧:

SW_FORCEMINIMIZE
Windows 2000/XP: Minimizes a window, even if the thread that owns the window is not responding. This flag should only be used when minimizing windows from a different thread.
SW_HIDE
Hides the window and activates another window.
SW_MAXIMIZE
Maximizes the specified window.
SW_MINIMIZE
Minimizes the specified window and activates the next top-level window in the Z order.
SW_RESTORE
Activates and displays the window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when restoring a minimized window.
SW_SHOW
Activates the window and displays it in its current size and position.
SW_SHOWDEFAULT
Sets the show state based on the SW_ value specified in the STARTUPINFO structure passed to the CreateProcess function by the program that started the application.
SW_SHOWMAXIMIZED
Activates the window and displays it as a maximized window.
SW_SHOWMINIMIZED
Activates the window and displays it as a minimized window.
SW_SHOWMINNOACTIVE
Displays the window as a minimized window. This value is similar to SW_SHOWMINIMIZED, except the window is not activated.
SW_SHOWNA
Displays the window in its current size and position. This value is similar to SW_SHOW, except the window is not activated.
SW_SHOWNOACTIVATE
Displays a window in its most recent size and position. This value is similar to SW_SHOWNORMAL, except the window is not actived.
SW_SHOWNORMAL
Activates and displays a window. If the window is minimized or maximized, the system restores it to its original size and position. An application should specify this flag when displaying the window for the first time.
------


蕭沖
--All ideas are worthless unless implemented--

C++ Builder Delphi Taiwan G+ 社群
http://bit.ly/cbtaiwan
系統時間:2024-05-10 10:10:44
聯絡我們 | Delphi K.Top討論版
本站聲明
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。
2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。
3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇!