CreateProcess doesn#39;t pass command line arguments(CreateProcess 不传递命令行参数)
问题描述
您好,我有以下代码,但没有按预期工作,无法弄清楚问题出在哪里.
Hello I have the following code but it isn't working as expected, can't figure out what the problem is.
基本上,我正在执行一个进程(一个 .NET 进程)并传递命令行参数,它由 CreateProcess() 成功执行,但 CreateProcess() 没有传递命令行参数
Basically, I'm executing a process (a .NET process) and passing it command line arguments, it is executed successfully by CreateProcess() but CreateProcess() isn't passing the command line arguments
我在这里做错了什么??
What am I doing wrong here??
int main(int argc, char* argv[])
{
PROCESS_INFORMATION ProcessInfo; //This is what we get as an [out] parameter
STARTUPINFO StartupInfo; //This is an [in] parameter
ZeroMemory(&StartupInfo, sizeof(StartupInfo));
StartupInfo.cb = sizeof StartupInfo ; //Only compulsory field
LPTSTR cmdArgs = "name@example.com";
if(CreateProcess("D:\email\smtp.exe", cmdArgs,
NULL,NULL,FALSE,0,NULL,
NULL,&StartupInfo,&ProcessInfo))
{
WaitForSingleObject(ProcessInfo.hProcess,INFINITE);
CloseHandle(ProcessInfo.hThread);
CloseHandle(ProcessInfo.hProcess);
printf("Yohoo!");
}
else
{
printf("The process could not be started...");
}
return 0;
}
嘿还有一件事,如果我像这样传递我的 cmdArgs
:
Hey one more thing, if I pass my cmdArgs
like this:
// a space as the first character
LPTSTR cmdArgs = " name@example.com";
然后我得到错误,然后 CreateProcess 返回 TRUE
但我的目标进程没有执行.
Then I get the error, then CreateProcess returns TRUE
but my target process isn't executed.
Object reference not set to an instance of an object
推荐答案
你应该在参数中指定还模块名称:LPTSTR cmdArgs = "App name@example.com";代码>它应该是整个命令行(包括 argv[0]).
You should specify also the module name in parameters: LPTSTR cmdArgs = "App name@example.com";
It should be the whole command line (including argv[0]).
这篇关于CreateProcess 不传递命令行参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:CreateProcess 不传递命令行参数


- STL 中有 dereference_iterator 吗? 2022-01-01
- 静态初始化顺序失败 2022-01-01
- 如何对自定义类的向量使用std::find()? 2022-11-07
- Stroustrup 的 Simple_window.h 2022-01-01
- 使用/clr 时出现 LNK2022 错误 2022-01-01
- 从python回调到c++的选项 2022-11-16
- 与 int by int 相比,为什么执行 float by float 矩阵乘法更快? 2021-01-01
- 近似搜索的工作原理 2021-01-01
- 一起使用 MPI 和 OpenCV 时出现分段错误 2022-01-01
- C++ 协变模板 2021-01-01