1 // NeL - MMORPG Framework <http://dev.ryzom.com/projects/nel/>
2 // Copyright (C) 2010 Winch Gate Property Limited
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU Affero General Public License as
6 // published by the Free Software Foundation, either version 3 of the
7 // License, or (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU Affero General Public License for more details.
14 // You should have received a copy of the GNU Affero General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
17 #include "nel/misc/debug.h"
23 int main(int argc
, char* argv
[])
28 printf ("exec_timeout [timeout(ms)] [prog.exe] [arg0] [arg1]...\nReturn 0:error, 1:ok, 2:timeout\n");
37 for (int i
=2; i
<argc
; i
++)
44 // Process information
45 PROCESS_INFORMATION process_info
;
48 DWORD timeout
= atoi (argv
[1]);
51 STARTUPINFO startupInfo
;
52 GetStartupInfo (&startupInfo
);
55 if (CreateProcess( NULL
, (char*)(argu
.c_str()), NULL
, NULL
, TRUE
, CREATE_NEW_PROCESS_GROUP
, NULL
, NULL
, &startupInfo
, &process_info
))
58 switch (WaitForSingleObject ( process_info
.hProcess
, timeout
))
65 if (TerminateProcess (process_info
.hProcess
, 0))
67 nlwarning ("ERROR: Timeout in process %s", (char*)(argu
.c_str()));
71 nlwarning ("ERROR: Error while terminate current process %s", (char*)(argu
.c_str()));
76 nlwarning ("ERROR: Error can't exec process %s", (char*)(argu
.c_str()));