运行 exe形成另一个exe并传递参数
Run exe form another exe and pass parameters
我正在尝试制作一个调用另一个 .exe 并将参数传递给它的程序。我的案例是创建一个程序来打开两个 (dosbox.exe) 并将命令传递给 运行 可执行文件。我正在尝试自动化测试过程。
我试过这样的代码
ShellExecute(NULL, "open", "C:\chat\DOSBox 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()
调用的 return 值以确保调用成功。
更新: 你问如何运行 在位于另一个文件夹中的单个dosbox 中前台的两个命令。您可以像这样嵌入完整路径:
std::system( "c:\MyDosBox\dosbox.exe -c c:\My\Progams\myCommand1.exe p1 p2 && c:\Other\myCommand2.exe p3 p4" );`
我正在尝试制作一个调用另一个 .exe 并将参数传递给它的程序。我的案例是创建一个程序来打开两个 (dosbox.exe) 并将命令传递给 运行 可执行文件。我正在尝试自动化测试过程。 我试过这样的代码
ShellExecute(NULL, "open", "C:\chat\DOSBox 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()
调用的 return 值以确保调用成功。
更新: 你问如何运行 在位于另一个文件夹中的单个dosbox 中前台的两个命令。您可以像这样嵌入完整路径:
std::system( "c:\MyDosBox\dosbox.exe -c c:\My\Progams\myCommand1.exe p1 p2 && c:\Other\myCommand2.exe p3 p4" );`