3737
3838using namespace wasm ;
3939
40+ // a timeout on every execution of the command
41+ size_t timeout = 2 ;
42+
4043struct ProgramResult {
4144 int code;
4245 std::string output;
@@ -51,10 +54,10 @@ struct ProgramResult {
5154 void getFromExecution (std::string command) {
5255 // do this using just core stdio.h and stdlib.h, for portability
5356 // sadly this requires two invokes
54- code = system ((" timeout 2s " + command + " > /dev/null 2> /dev/null" ).c_str ());
57+ code = system ((" timeout " + std::to_string (timeout) + " s " + command + " > /dev/null 2> /dev/null" ).c_str ());
5558 const int MAX_BUFFER = 1024 ;
5659 char buffer[MAX_BUFFER];
57- FILE *stream = popen ((" timeout 2s " + command + " 2> /dev/null" ).c_str (), " r" );
60+ FILE *stream = popen ((" timeout " + std::to_string (timeout) + " s " + command + " 2> /dev/null" ).c_str (), " r" );
5861 while (fgets (buffer, MAX_BUFFER, stream) != NULL ) {
5962 output.append (buffer);
6063 }
@@ -526,6 +529,12 @@ int main(int argc, const char* argv[]) {
526529 [&](Options* o, const std::string& argument) {
527530 force = true ;
528531 })
532+ .add (" --timeout" , " -to" , " A timeout to apply to each execution of the command, in seconds (default: 2)" ,
533+ Options::Arguments::One,
534+ [&](Options* o, const std::string& argument) {
535+ timeout = atoi (argument.c_str ());
536+ std::cout << " |applying timeout: " << timeout << " \n " ;
537+ })
529538 .add_positional (" INFILE" , Options::Arguments::One,
530539 [&](Options* o, const std::string& argument) {
531540 input = argument;
0 commit comments