我对CreateProcessA有一个问题,我在堆栈溢出和其他站点上查看了有关它的所有问题,我按照其他人的建议重写了一个程序,但是它仍然没有执行任何命令并返回错误998。我确信字符串是正确的,因为它既适用于系统,又直接写在cmd上。我真的不知道该怎么办了。我也读过它是如何工作的,但我不想工作。对不起,如果我的英语不好,感谢那些回答我。
#include <iostream>
#include <windows.h>
using namespace std;
int main()
{
STARTUPINFOA si;
si.cb = sizeof(si);
PROCESS_INFORMATION pi;
string com="\"C:\\Program Files\\MKVToolNix\\mkvextract.exe\" \"D:\\Anime recuperati\\BKT\\Caricati\\[BKT] Jormungand 01-12 END BDRip\\Jormungand - Ep01.mkv\" attachments -f 1:\"C:\\Users\\Utente\\Desktop\\Subs\\n\\Jormungand - Ep01\\Justus-Bold.ttf\"";
CreateProcessA(NULL,const_cast<char *>(com.c_str()),NULL,NULL,FALSE,0,NULL,NULL,&si,&pi);
cout<<GetLastError();
return 0;
}
发布于 2022-07-31 22:42:24
您传递未初始化的STARTUPINFOA si;
。必须初始化它。见示例。
#include <iostream>
#include <string>
#include <windows.h>
using std::cout;
using std::string;
int main()
{
STARTUPINFOA si{sizeof(si)};
PROCESS_INFORMATION pi{};
string com = R"("C:\Program Files\MKVToolNix\mkvextract.exe" "D:\Anime recuperati\BKT\Caricati\[BKT] Jormungand 01-12 END BDRip\Jormungand - Ep01.mkv" attachments -f 1:"C:\Users\Utente\Desktop\Subs\n\Jormungand - Ep01\Justus-Bold.ttf)";
CreateProcessA(nullptr, const_cast<char *>(com.c_str()), nullptr, nullptr, false, 0, nullptr, nullptr, &si, &pi);
cout<<GetLastError();
return 0;
}
#include <string>
,请使用std::string
。R"(...)"
避免使用转义序列。nullptr
中使用C++。false
中使用C++。https://stackoverflow.com/questions/73187217
复制相似问题