Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #elif __linux
- g_pSM->BuildPath(Path_SM, szInFilePath, sizeof(szInFilePath), "scripting/nextmap.sp");
- g_pSM->BuildPath(Path_SM, szOutFilePath, sizeof(szOutFilePath), "scripting/nextmap.smx");
- g_pSM->Format(szCMDLine, sizeof(szCMDLine), "-o%s", szOutFilePath);
- g_pSM->BuildPath(Path_SM, szCompilerPath, sizeof(szCompilerPath), "scripting/spcomp");
- LogMessageEx("szInFilePath: %s", szInFilePath);
- LogMessageEx("szOutFilePath: %s", szOutFilePath);
- LogMessageEx("szCMDLine: %s", szCMDLine);
- LogMessageEx("szCompilerPath: %s", szCompilerPath);
- // F:\CSS\SteamCMD\csgo_server\csgo\addons\sourcemod\scripting\spcomp.exe
- int pipe1[2];
- int fd[2];
- pid_t pid;
- char ch;
- char *szBuffer = new char[(size_t)(sizeof(char) * 4028];
- int outcount = 0;
- pipe(fd);
- switch (pid = fork())
- {
- case -1:
- {
- g_pSM->LogError(myself, "fork");
- break;
- }
- case 0:
- {
- close(fd[0]);
- dup2(fd[1], 1);
- execl(szCompilerPath, "spcomp", "-O2", /*szCMDLine, */szInFilePath, NULL);
- close(fd[1]);
- exit(pid);
- break;
- }
- default:
- {
- LogMessageEx("Output from child:\n");
- close(fd[1]);
- while (read(fd[0], &ch, 1) == 1)
- {
- write(1, &ch, 1);
- szBuffer[outcount++] = ch;
- }
- close(fd[0]);
- *(szBuffer + outcount) = '\0';
- LogMessageEx("%s\n", szBuffer);
- LogMessageEx("Total characters out: %d\n", outcount);
- }
- }
- delete [] szBuffer;
- #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement