2013-12-15 40 views
0

在我的C++應用程序,這是一個.exe一個應用程序,我有這樣的:C#調用使用命令行

int main(int argc, char** argv){ 
--argc; 
++argv; 
if (argc != 1){ 
    throw std::exception("Bad command line."); 
} 

但我怎麼會叫,在我的C#(WPF)的應用程序?我試過System.Diagnostics.Process.Start("pathofapp.exe", "stringiwantedtouse"),但我得到了Bad Command Line。我該怎麼辦?

回答

1

你應該嘗試使用C++程序是這樣的:

int main (int argc, char *argv[]) 
{ 
    if (argc != 1){ 
     throw std::exception("Bad command line."); 
    } 
} 

然後使用的argv [0]進入它的第一個參數。

例如:

在C++:

int main (int argc, char *argv[]) 
{ 
    if (argc != 1){ 
     throw std::exception("Bad command line."); 
    }else{ 
     std::cout << "Param 1: " << argv[0] << std::endl; 
    } 
} 

在C#:

System.Diagnostics.Process.Start("pathofapp.exe", "this"); 

輸出:

Param 1: this 
0
System.Diagnostics.Process.Start("pathofapp.exe", "stringiwantedtouse")