CreateProcess不传递命令行参数 [英] CreateProcess doesn't pass command line arguments

查看:652
本文介绍了CreateProcess不传递命令行参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我有以下代码,但它不能正常工作,不能弄清楚问题是什么。



基本上,我执行进程(.NET进程)并传递命令行参数,它由CreateProcess()成功执行,但CreateProcess()不传递命令行参数



我在这里做错了吗

  int main(int argc,char * argv [])
{
PROCESS_INFORMATION ProcessInfo; //这是我们获得的一个[out]参数

STARTUPINFO StartupInfo; //这是一个[in]参数

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(无法启动进程...);
}

return 0;
}

EDIT:像这样传递 cmdArgs

  // character 
LPTSTR cmdArgs =name@example.com;

然后我得到错误,然后CreateProcess返回 TRUE

 对象引用未设置为对象的实例


解决方案

您应该在参数中指定 LPTSTR cmdArgs =App name@example.com;
它应该是整个命令行(包括argv [0])。


Hello I have the following code but it isn't working as expected, can't figure out what the problem is.

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;
}

EDIT: Hey one more thing, if I pass my cmdArgs like this:

// a space as the first character
LPTSTR cmdArgs = " name@example.com";

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

解决方案

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不传递命令行参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆