【问题标题】:Calling (cpp) "App.exe" From Matlab using "System" command使用“系统”命令从 Matlab 调用(cpp)“App.exe”
【发布时间】:2012-05-01 15:43:58
【问题描述】:

我正在尝试从 matlab 调用“App.exe”文件(用 cpp 编写),该文件将视频名称(字符串)作为输入

我想使用“系统”函数来执行操作系统命令并将结果返回给 Matlab。

我在 Matlab 中写了以下内容:

 system ('App.exe <'  VideoName);

以及 Cpp 中的以下内容:

 // to get the name of the video (the input) from the command.
 std::string str;
 getline(cin, str);
 const char * name = str.c_str();

但它不起作用。 所以我的问题是:我们如何通过输入从 matlab(甚至 cmd)调用“App.exe”。 我应该怎么做才能完成这项工作?

【问题讨论】:

    标签: c++ matlab command-line cmd


    【解决方案1】:

    我不熟悉 matlab 语法,但您可能应该尝试将整个路径放入 App.exe。Matlab 的工作目录可能与 App.exe 所在的目录不同。或者,您可以将 App.exe 所在的目录添加到您的 PATH 环境变量中(然后重新启动 matlab 以确保它获得新值)。

    【讨论】:

    • 它在同一个目录下,我把matlab文件和“app.exe”工作区放在同一个目录下。如果您不熟悉 matlab,那么我的问题是:如何从 Cmd 调用“app.exe”?写什么(改变路径后)?!注意它得到一个字符串作为输入
    • 但是 app.exe 需要一个输入。如何添加?
    • 通常您会使用 argv 将输入作为参数传递。然后你可以运行 cmd /c "/path/to/app.exe input" 而不必担心重定向。在这种情况下,输入将在 argv[1] 中。
    • 在 Cmd 中调用以下命令:“app.exe nameOfvid”,然后在 C++ 中执行以下操作:“std::string str = argv[1]; const char * nameOfvid = str.c_str ();" ?!!!!?!
    • 你可以做 const char* nameOfvid = argv[1];.
    猜你喜欢
    • 2011-05-23
    • 1970-01-01
    • 2015-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-29
    相关资源
    最近更新 更多