[問題] 呼叫外部執行檔路徑設定
開發平台(Platform): (Ex: VC++, GCC, Linux, ...)
VC++ (MFC)
額外使用到的函數庫(Library Used): (Ex: OpenGL, ...)
N/A
問題(Question):
我用MFC寫了一個Dialog Base的小程式
其中一個功能是透過 Build.cmd 去呼叫外部程式
這個Build.cmd 內容是依照使用者給定的資料去輸出產生的
Build.cmd 和 外部程式希望跟主程式放在同一個目錄
想知道執行到
ShellExecuteEx(&ShExecInfo) 這一行時
如何使主程式是在目前路徑去找Build.cmd
餵入的資料(Input):
預期的正確結果(Expected Output):
在主程式相同路徑下去執行Build.cmd
錯誤結果(Wrong Output):
Build.cmd被產生的路徑不如預期
程式碼(Code):(請善用置底文網頁, 記得排版)
// 產生Build.cmd
CFile build(_T("Build.cmd"),CFile::modeCreate|CFile::modeWrite);
....
....
build.Write(strContent.GetBuffer(),strContent.GetLength());
build.Close();
// 執行Build.cmd
SHELLEXECUTEINFO ShExecInfo = {0};
ShExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
ShExecInfo.fMask = SEE_MASK_NOCLOSEPROCESS;
ShExecInfo.hwnd = NULL;
ShExecInfo.lpVerb = NULL;
ShExecInfo.lpFile = _T("Build.cmd");
ShExecInfo.lpParameters = NULL;
ShExecInfo.lpDirectory = NULL;
ShExecInfo.nShow = SW_SHOW; // Or隱藏 SW_HIDE
ShExecInfo.hInstApp = NULL;
ShellExecuteEx(&ShExecInfo);
WaitForSingleObject(ShExecInfo.hProcess,INFINITE);
Build_WIM.cmd 只有一行內容
ABC.exe /參數1 /參數2 /參數3 ......
補充說明(Supplement):
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 210.63.100.2
→
12/09 13:19, , 1F
12/09 13:19, 1F
→
12/09 13:20, , 2F
12/09 13:20, 2F
→
12/09 13:21, , 3F
12/09 13:21, 3F
→
12/09 14:07, , 4F
12/09 14:07, 4F
→
12/09 14:08, , 5F
12/09 14:08, 5F
→
12/09 14:08, , 6F
12/09 14:08, 6F
→
12/09 23:02, , 7F
12/09 23:02, 7F
→
12/09 23:02, , 8F
12/09 23:02, 8F
→
12/09 23:31, , 9F
12/09 23:31, 9F
→
12/09 23:32, , 10F
12/09 23:32, 10F
C_and_CPP 近期熱門文章
PTT數位生活區 即時熱門文章