Skip to content
This repository has been archived by the owner on Oct 28, 2019. It is now read-only.

Commit

Permalink
Fix runner on mac
Browse files Browse the repository at this point in the history
  • Loading branch information
panyz522 committed Oct 20, 2019
1 parent 40b36a7 commit 336d98e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
21 changes: 18 additions & 3 deletions Data/Runner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,16 @@ public async Task<(string, bool, double)> Run()
this.Bash(this.CmdString, this.WordDir);
}

this.process.Start();
try
{
this.process.Start();
}
catch (Exception e)
{
this.Log.LogError(e.ToString());
return ($"Process start error! Please check command and workdir.\n{e.Message}", true, 0);
}

bool finished = true;
using (var cts = new CancellationTokenSource((int)((this.BoundBoardManager?.TimeLeft ?? 10f) * 1000))) // Default to wait 10s
{
Expand All @@ -80,16 +89,22 @@ public async Task<(string, bool, double)> Run()
catch (TaskCanceledException)
{
this.Log.LogInformation("Execution Cancelled.");
finished = false;
finished = true;
}
}

if (!finished)
{
this.process.Kill(true);
}
string result = await this.process.StandardOutput.ReadToEndAsync();
var usedTime = this.process.UserProcessorTime.TotalSeconds;

double usedTime = 0;
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
usedTime = this.process.UserProcessorTime.TotalSeconds;

this.process.Dispose();

if (this.BoundBoardManager != null)
this.BoundBoardManager.TimeUsedInRunner = usedTime;
return (result, finished, usedTime);
Expand Down
2 changes: 1 addition & 1 deletion Pages/RunnerPage.razor
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
</div>
</div>

<br/>
<br />

<div class="row">
<div class="col-sm-10">
Expand Down
9 changes: 8 additions & 1 deletion appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
"FilePath": "c:\\Users\\Turnip\\Documents\\CS561\\Hws\\Hw2\\input.txt",
"OutputFilePath": "c:\\Users\\Turnip\\Documents\\CS561\\Hws\\Hw2\\output.txt",
"WorkDir": "c:\\Users\\Turnip\\Documents\\CS561\\Hws\\Hw2\\",
"Cmd": "python python3.py"
"Cmd": "python homework3.py"

// A Sample for Mac or Linux:

//"FilePath": "/home/user/cs561/hw2/input.txt",
//"OutputFilePath": "/home/user/cs561/hw2/output.txt",
//"WorkDir": "/home/user/cs561/hw2/",
//"Cmd": "python3 homework3.py" // or "./homework" if it is executable.
}
}

0 comments on commit 336d98e

Please sign in to comment.