考虑以下代码及其可执行文件 - runner.exe
:
#include <iostream>
#include <string>
#include <windows.h>
using namespace std;
int main(int argc, char *argv[])
{
SHELLEXECUTEINFO shExecInfo;
shExecInfo.cbSize = sizeof(SHELLEXECUTEINFO);
shExecInfo.fMask = NULL;
shExecInfo.hwnd = NULL;
shExecInfo.lpVerb = "open";
shExecInfo.lpFile = argv[1];
string Params = "";
for ( int i = 2; i < argc; ++i )
Params += argv[i] + ' ';
shExecInfo.lpParameters = Params.c_str();
shExecInfo.lpDirectory = NULL;
shExecInfo.nShow = SW_SHOWNORMAL;
shExecInfo.hInstApp = NULL;
ShellExecuteEx(&shExecInfo);
return 0;
}
这两个批处理文件都做了它们应该做的事情,即运行 notepad.exe 并运行 notepad.exe 并告诉它尝试打开 test.txt:
1.
runner.exe notepad.exe
2.
runner.exe notepad.exe test.txt
现在,考虑这个批处理文件:
3.
runner.exe runner.exe notepad.exe
这个应该运行 runner.exe 并将 notepad.exe 作为其命令行参数之一发送,不是吗?然后,runner.exe 的第二个实例应该运行 notepad.exe - 这不会发生,我收到“Windows 找不到 'am'。确保您输入了正确的名称,然后再试一次”错误。如果我打印argc
参数,则runner.exe 的第二个实例是14,它们都是奇怪的东西,比如 Files\Microsoft、SQL、Files\Common 等等。我不明白为什么会这样。我希望能够使用命令行参数将尽可能多的 runner.exe 调用串起来,或者至少 2 个。我该怎么做?
如果这有所作为,我正在使用 Windows 7。