我有这个功能(该函数获取一个命令作为参数并执行一些东西,我创建类似自定义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方法运行它?