2017-08-01 95 views
0

我試圖用命令行的輸入參數調用我的MFC應用程序。使用參數+ stdout + stderr從命令行調用MFC應用程序

我想應用程序打印輸出到一個文件和錯誤到另一個文件。

所以除了輸入參數之外,我通過了1>out.txt 2>err.txt

總體而言,在命令行看起來類似:

start /w app.exe arg1 arg2 arg3 1>out.txt 2>err.txt 

這似乎給了一小會兒工作,結果寫入兩個文件。

但是,在某個時候停止了,所以我想我做錯了什麼。

這裏是我的代碼:

頭文件:

class CMyWinApp : public CWinApp 
{ 
public: 
    BOOL InitInstance(); 
}; 

源文件:

CMyWinApp myWinApp; 

BOOL CMyWinApp::InitInstance() 
{ 
    CWinApp::InitInstance();  
    int iNumOfArgs; 
    LPWSTR* pArgs = CommandLineToArgvW(GetCommandLine(),&iNumOfArgs); 
    for (int iArgNum=1; iArgNum<iNumOfArgs; iArgNum++) 
    { 
     fprintf(stdout,"%ls\n",pArgs[iArgNum]); 
     fprintf(stderr,"%ls\n",pArgs[iArgNum]); 
    } 
} 

究竟我做錯了的是什麼?

謝謝。

回答

0

OK,問題就迎刃而解了:

我加入了start /w在某些時候,爲了迫使等待完成。

由於某種原因,因此沒有任何內容寫入到兩個目標文件中。

相關問題