CreateProcess Windows.h c ++如何将一个函数作为一个进程运行?

时间:2016-04-09 18:43:51

标签: c++ process

我有这个功能(该函数获取一个命令作为参数并执行一些东西,我创建类似自定义cmd的东西:

int execute(Line* line)
{
    string command = line->command;
    if (command == "echo")
    {
        cout << line->parameter << endl;
    }
    else if (command == "dir")
    {
        cout << ExePath() << endl;
    }
    else if (command == "cd")
    {
        const char* newDir = line->parameter.c_str();
        if (!SetCurrentDirectory(newDir)) {
            std::cerr << "Error setting current directory: #" << GetLastError() << endl;
            return 1; // quit if we couldn't set the current directory
        }
        std::cout << "Set current directory to " << newDir << '\n';
    }
    else if (command == "exit")
    {
        exit(0);
    }

    exit(1);
} 

如何通过windows.h的CreateProcess方法运行它?

0 个答案:

没有答案