在我的 C++ 应用程序中,它是一个 .exe
,我有这个:
int main(int argc, char** argv){
--argc;
++argv;
if (argc != 1){
throw std::exception("Bad command line.");
}
E.t.c
但我如何在我的 C# (WPF) 应用程序中调用它?我尝试了 System.Diagnostics.Process.Start("pathofapp.exe", "stringiwantedtouse")
,但我得到了 Bad Command Line
。我该怎么办?
最佳答案
你应该尝试像这样使用 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
关于C# 使用命令行调用应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20594304/