Advertisement
BM_R1KO

Untitled

Nov 9th, 2017
264
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #elif __linux
  2.     g_pSM->BuildPath(Path_SM, szInFilePath, sizeof(szInFilePath), "scripting/nextmap.sp");
  3.     g_pSM->BuildPath(Path_SM, szOutFilePath, sizeof(szOutFilePath), "scripting/nextmap.smx");
  4.     g_pSM->Format(szCMDLine, sizeof(szCMDLine), "-o%s", szOutFilePath);
  5.     g_pSM->BuildPath(Path_SM, szCompilerPath, sizeof(szCompilerPath), "scripting/spcomp");
  6.     LogMessageEx("szInFilePath: %s", szInFilePath);
  7.     LogMessageEx("szOutFilePath: %s", szOutFilePath);
  8.     LogMessageEx("szCMDLine: %s", szCMDLine);
  9.     LogMessageEx("szCompilerPath: %s", szCompilerPath);
  10.     // F:\CSS\SteamCMD\csgo_server\csgo\addons\sourcemod\scripting\spcomp.exe
  11.  
  12.  
  13.     int pipe1[2];
  14.  
  15.     int     fd[2];
  16.     pid_t   pid;
  17.  
  18.     char ch;
  19.     char *szBuffer = new char[(size_t)(sizeof(char) * 4028];
  20.     int outcount = 0;
  21.     pipe(fd);
  22.  
  23.     switch (pid = fork())
  24.     {
  25.     case -1:
  26.         {
  27.             g_pSM->LogError(myself, "fork");
  28.             break;
  29.         }
  30.  
  31.     case 0:
  32.         {
  33.             close(fd[0]);
  34.             dup2(fd[1], 1);
  35.             execl(szCompilerPath, "spcomp", "-O2", /*szCMDLine, */szInFilePath, NULL);
  36.             close(fd[1]);
  37.             exit(pid);
  38.             break;
  39.         }
  40.     default:
  41.         {
  42.  
  43.             LogMessageEx("Output from child:\n");
  44.             close(fd[1]);
  45.             while (read(fd[0], &ch, 1) == 1)
  46.             {
  47.                 write(1, &ch, 1);
  48.                 szBuffer[outcount++] = ch;
  49.             }
  50.             close(fd[0]);
  51.             *(szBuffer + outcount) = '\0';
  52.             LogMessageEx("%s\n", szBuffer);
  53.             LogMessageEx("Total characters out: %d\n", outcount);
  54.         }
  55.     }
  56.  
  57.     delete [] szBuffer;
  58.  
  59.     #endif
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement