forked from pythonnet/pythonnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
53 lines (47 loc) · 1.74 KB
/
Program.cs
File metadata and controls
53 lines (47 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using NUnit.Common;
using NUnitLite;
using Python.Runtime;
namespace Python.EmbeddingTest
{
public class Program
{
public static int Main(string[] args)
{
if (args.Contains("--loop"))
{
args = args.Where(x => x != "--loop").ToArray();
int result;
int runNumber = 0;
string pathEnv = Environment.GetEnvironmentVariable("PATH");
do
{
Console.ForegroundColor = ConsoleColor.Green;
Console.Error.WriteLine($"----- Run = {++runNumber}, MemUsage = {Process.GetCurrentProcess().WorkingSet64 / 1024 / 1024} Mb -----");
Console.ForegroundColor = ConsoleColor.Gray;
result = new AutoRun(typeof(Program).Assembly).Execute(
args,
new ExtendedTextWrapper(Console.Out),
Console.In);
// Python does not see Environment.SetEnvironmentVariable changes.
// So we needs restore PATH variable in a pythonic way.
using (new PythonEngine())
{
dynamic os = PythonEngine.ImportModule("os");
os.environ["PATH"] = new PyString(pathEnv);
}
}
while (!Console.KeyAvailable);
return result;
}
return new AutoRun(typeof(Program).Assembly).Execute(
args,
new ExtendedTextWrapper(Console.Out),
Console.In);
}
}
}