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
  • 4
  • Yeah . This should be reopened As i worked hard to find the solution . – shawon Feb 10 '17 at 11:07
  • Voted to reopen. As techraf noted, we're a bit different than forums - Super User is a Q&A site. You've found an answer to your question, it's not only okay to post it as an answer but it's also encouraged: it makes it easier for others with this problem to realize that you've actually found a solution. Moreover, you'll be getting reputation for every upvote on that answer too. Please post an answer with your solution and remove it from question. – gronostaj Feb 10 '17 at 11:13
  • Yet it is closed @gronostaj – shawon Feb 10 '17 at 11:23
  • so why don't just post the answer on the other duplicate question? – phuclv Feb 10 '17 at 11:26
  • You're right, sorry. I should get some sleep ;) – gronostaj Feb 10 '17 at 11:31
  • I see you posted your answer to the marked duplicate question. Please edit your question to remove the answer. Thanks for contributing to Super User. – I say Reinstate Monica Feb 10 '17 at 16:41

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
  • 4