gpt4 book ai didi

c++ - system() C++ 中的空格

转载 作者:行者123 更新时间:2023-11-28 03:31:22 25 4
gpt4 key购买 nike

我尝试了一些在 Stackoverflow 中找到的解决方案,但我无法让它工作,我想从 C++ 启动一个 .LOG(.txt 文件),但包含它的路径文件夹可能有空格,所以当我尝试启动它时,我收到一条错误消息,说它找不到文件,因为 pah(包含空格)是错误的,这是我的代码:

void Log (unsigned int Code,...)
{
char currdate[11] = {0};
SYSTEMTIME t;
GetLocalTime(&t);
sprintf(currdate, "%02d:%02d:%02d", t.wHour, t.wMinute, t.wSecond);

PROCESSENTRY32 pe32;
FILE* FileHwnd1;

FileHwnd1 = fopen("TEST.log","a+");
fprintf(FileHwnd1,"[%s] Code: %X\n",currdate,Code);
fclose(FileHwnd1);
char buffer[MAX_PATH];
GetModuleFileName( NULL, buffer, MAX_PATH);
char Path[50];

wsprintf(Path,"start %s\\AntiHack.log",buffer);
system(Path);//Here is where i get the containing spaces path error
}

谢谢。

最佳答案

我建议您完全避免系统调用并自行启动进程。

  1. 使用AssocQueryString () 找到你的关联进程扩展名(在本例中为 .log)
  2. 设置并启动 CreateProcess () 调用调用,传递适当的命令行。

还有其他方法可以做到这一点,但正如您现在所注意到的,迂回曲折的方式总会有陷阱。以上内容准确地说明了 Explorer.exe 如何启动扩展的关联进程。

关于c++ - system() C++ 中的空格,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12488267/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com