0

I am developing an online judge for my university. I need to timeout every program after 5 seconds for measuring time limit. my input is input.txt file and i am compiling and getting output in ubuntu by these commands

g++ -lm tle.cpp
timeout 5s a.exe < input.txt

These commands allow cpu to run programs for only 5 seconds. Now I need equivalent commands for Windows cmd.

Edit :

This Question is different from previous one as windows timeout process is different from ubuntu timeout process. Windows timeout process just waits but not set a definite time for execution. if execution is done before timeout then windows timeout still waits where ubuntu timeout set a definite time for program execution and terminates after execution but does not wait though program is terminated. So i want to stop waiting if execution is finished.

shawon
  • 141

1 Answers1

1

Solution :

By The Way I have found my solution. In windows it needs to make three batch files

process.bat

@ECHO OFF
start   /b cm.bat
start  cmd.exe /c run.bat
EXIT

cm.bat

@ECHO OFF
a.exe < input.txt > out.txt
taskkill /im a.exe /f
taskkill /im cmd.exe /f
EXIT

run.bat

@ECHO off
timeout /t 5
taskkill /im a.exe /f 
taskkill /im cmd.exe /f

EXIT

Now Run process.bat . it will start both cm.bat and run.bat simultaneously/parallely. When a.exe from cm.bat terminates; cm.bat kills run.bat and thus it will work as ubuntu timeout.

shawon
  • 141