我正在使用以下命令在 C 中创建三个子进程:
typedef struct{
STARTUPINFO si;
PROCESS_INFORMATION pi;
}PROCESS_PARAMS;
PROCESS_PARAMS pChildren[3];
wchar_t *szCmdline[3] = {L"nmtest -s \"TS\" -r \"Test DMR\" -tLD -d \" /child1/tclient\"",
L"nmtest -s \"TS\" -r \"Test DMR\" -tLD -d \" /child2/tclient\"",
L"nmtest -s \"TS\" -r \"Test DMR\" -tLD -d \" /child3/tclient\""};
for (i=0; i<3; i++)
{
pChildren[i].si.cb = sizeof(pChildren[i].si);
GetStartupInfo(&pChildren[i].si);
ZeroMemory(&pChildren[i].pi, sizeof(pChildren[i].pi));
// Start the child processes.
CreateProcess(NULL, // No module name (use command line)
szCmdline[i], // Command line
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
0, // No creation flags
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&pChildren[i].si, // Pointer to STARTUPINFO structure
&pChildren[i].pi); // Pointer to PROCESS_INFORMATION structure
}
但是代码在创建新进程时崩溃了,我怀疑命令行参数有问题。但我不确定出了什么问题。有人可以帮我吗?谢谢。
PS:当我以以下方式给出它时,它会起作用:
wchar_t szCmdline[] = L"nmctest -s \"TwonkyServer[julka]\" -r \"NMC Test DMR [julka960]\" -tLDMR -d \" /child1/twonkyclient\"";
然后在我做:
CreateProcess(NULL, // No module name (use command line)
szCmdline, // Command line
NULL, // Process handle not inheritable
NULL, // Thread handle not inheritable
FALSE, // Set handle inheritance to FALSE
0, // No creation flags
NULL, // Use parent's environment block
NULL, // Use parent's starting directory
&pChildren[i].si, // Pointer to STARTUPINFO structure
&pChildren[i].pi);
请注意,我给出的是 szCmdline 而不是 szCmdline[i]。然后它可以工作,但我不确定最顶层代码中的问题何时出现。