Team Fortress 2 Source Code as on 22/4/2020
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

53 lines
1.5 KiB

  1. //========= Copyright Valve Corporation, All rights reserved. ============//
  2. //
  3. // Purpose: a very simple wrapper to spawn another process based upon the contents of runme.dat
  4. //
  5. //=============================================================================
  6. #include <stdio.h>
  7. #define WIN32_LEAN_AND_MEAN
  8. #include <windows.h>
  9. int APIENTRY WinMain( HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow )
  10. {
  11. // runme.dat contains the command line to run (passed directly to createprocess() )
  12. FILE *f = fopen( "runme.dat", "rb" );
  13. if ( !f )
  14. return -1;
  15. char szCommand[MAX_PATH];
  16. memset( szCommand, 0x0, sizeof(szCommand) );
  17. fread( szCommand, sizeof(szCommand), 1, f );
  18. fclose( f );
  19. int iCh = 0;
  20. while ( iCh < sizeof(szCommand) && szCommand[ iCh ] && szCommand[ iCh ] != '\r' && szCommand[ iCh ] != '\n' )
  21. {
  22. iCh++;
  23. }
  24. szCommand[ iCh ] = ' ';
  25. szCommand[ iCh + 1 ] = 0;
  26. strncpy( &szCommand[ iCh + 1 ], lpCmdLine, sizeof(szCommand) - iCh - 1 );
  27. szCommand[ sizeof(szCommand) - 1 ] = 0;
  28. STARTUPINFO si;
  29. PROCESS_INFORMATION pi;
  30. memset(&si, 0x0, sizeof(si));
  31. si.cb = sizeof(si);
  32. memset(&pi, 0x0, sizeof(pi));
  33. // run the command
  34. if(!CreateProcess(NULL, szCommand, 0, 0, FALSE, NORMAL_PRIORITY_CLASS, 0, 0,&si, &pi))
  35. {
  36. return -1;
  37. }
  38. // Wait until child process exits.
  39. WaitForSingleObject( pi.hProcess, INFINITE );
  40. // Close process and thread handles.
  41. CloseHandle( pi.hProcess );
  42. CloseHandle( pi.hThread );
  43. return 0;
  44. }