运行EXE形成另一个EXE并传递参数

Run exe form another exe and pass parameters

本文关键字:EXE 参数 另一个 运行      更新时间:2023-10-16

我正在尝试制作一个调用另一个.exe并传递参数的程序。我的情况是创建一个程序以打开两个(dosbox.exe)并传递命令以运行可执行文件。我正在尝试自动化测试过程。我尝试过这样的代码

ShellExecute(NULL, "open", "C:chatDOSBox 0.74.lnk.exe", NULL, NULL, SW_SHOWDEFAULT);

,但它甚至没有用。有帮助吗?

怎么样: std::system( "dosbox -c myCommand" );(假设dosbox.exe和您的自定义myCommand.exe在您的路径中)?

在后台开始两个,做:

std::system( "start dosbox -c myCommand1" );
std::system( "start dosbox -c myCommand2" );
// Program has launched these in the background
// and continues execution here.

另外,您可以为每个std::system()调用一个线程:

auto cmd1 = std::async( [] { std::system( "dosbox -c myCommand1" ); } );
auto cmd2 = std::async( [] { std::system( "dosbox -c myCommand2" ); } );
// Program is launching these in the background
// and continues execution here.

您可能还需要检查每个std::system()调用的返回值以确保其成功。


update :您询问如何在一个位于另一个文件夹中的单个dosbox中的前景中运行两个命令。您可以像这样嵌入完整的路径:

std::system( "c:\MyDosBox\dosbox.exe -c c:\My\Progams\myCommand1.exe p1 p2 && c:\Other\myCommand2.exe p3 p4" );`