-
Notifications
You must be signed in to change notification settings - Fork 0
/
CGIwrap.cs
49 lines (43 loc) · 1.56 KB
/
CGIwrap.cs
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
using System;
using System.Diagnostics;
using System.Linq;
namespace CGIwrap
{
class Program
{
static void Main(string[] args)
{
var process = new Process();
process.StartInfo = new ProcessStartInfo
{
FileName = args[0],
Arguments = String.Join(" ", args.Skip(1).ToArray()),
UseShellExecute = false,
RedirectStandardInput = true,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true
};
process.OutputDataReceived += (sender, e) =>
{
Console.WriteLine(e.Data);
};
process.ErrorDataReceived += (sender, e) =>
{
Console.Error.WriteLine(e.Data);
};
process.Start();
process.BeginOutputReadLine();
process.BeginErrorReadLine();
// For some reason does Console.In.ReadToEnd() not work with data from IIS - the process just hang
// That's why we trust CONTENT_LENGTH instead
for (UInt32 i = 0; i < UInt32.Parse(Environment.GetEnvironmentVariable("CONTENT_LENGTH")); i++)
{
// Yeah, reading one char at a time isn't good for performance - but the whole concept of PowerShell CGI isn't about speed!
process.StandardInput.Write((char)Console.In.Read());
}
process.StandardInput.Close();
process.WaitForExit();
}
}
}