-
Notifications
You must be signed in to change notification settings - Fork 0
/
ShowOutput.cs
107 lines (94 loc) · 3.6 KB
/
ShowOutput.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using Bricksoft.PowerCode;
namespace ViewStandardIn
{
class ShowOutput
{
static int Main( string[] args )
{
bool optWait = false;
string tmpfile = "";
string input = "";
Process p;
ProcessStartInfo startInfo;
for (int i = 0; i < args.Length; i++) {
string a = args[i].Trim();
if (a.Equals("version", StringComparison.CurrentCultureIgnoreCase)
|| a.Equals("--version", StringComparison.CurrentCultureIgnoreCase)
|| a.Equals("-version", StringComparison.CurrentCultureIgnoreCase)
|| a.Equals("/version", StringComparison.CurrentCultureIgnoreCase)) {
DisplayVersion(true);
return 0;
} else if (a.Equals("--v", StringComparison.CurrentCultureIgnoreCase)
|| a.Equals("-v", StringComparison.CurrentCultureIgnoreCase)
|| a.Equals("/v", StringComparison.CurrentCultureIgnoreCase)) {
DisplayVersion(false);
return 0;
} else if (a.Equals("wait", StringComparison.CurrentCultureIgnoreCase)
|| a.Equals("--wait", StringComparison.CurrentCultureIgnoreCase)
|| a.Equals("-wait", StringComparison.CurrentCultureIgnoreCase)
|| a.Equals("/wait", StringComparison.CurrentCultureIgnoreCase)
|| a.Equals("-w", StringComparison.CurrentCultureIgnoreCase)
|| a.Equals("/w", StringComparison.CurrentCultureIgnoreCase)) {
optWait = true;
} else if (a.Equals("file", StringComparison.CurrentCultureIgnoreCase)
|| a.Equals("--file", StringComparison.CurrentCultureIgnoreCase)
|| a.Equals("-file", StringComparison.CurrentCultureIgnoreCase)
|| a.Equals("/file", StringComparison.CurrentCultureIgnoreCase)
|| a.Equals("-f", StringComparison.CurrentCultureIgnoreCase)
|| a.Equals("/f", StringComparison.CurrentCultureIgnoreCase)) {
if (i == args.Length - 1) {
DisplayVersion(true);
Console.Out.WriteLine();
Console.Error.WriteLine(" **** ERROR: --file is missing file name", a);
return 4;
}
tmpfile = args[i + 1];
input = File.ReadAllText(tmpfile);
} else {
DisplayVersion(true);
Console.Out.WriteLine();
Console.Error.WriteLine(" **** ERROR: unknown command: {0}", a);
return 3;
}
}
if (!ConsoleEx.IsInputRedirected && (args.Length == 0 || tmpfile.Length == 0)) {
DisplayVersion(true);
Console.Out.WriteLine();
Console.Error.WriteLine(" **** ERROR: missing content to display");
return 1;
}
// Read stdin
if (ConsoleEx.IsInputRedirected && tmpfile.Length == 0) {
input = Console.In.ReadToEnd();
tmpfile = Path.GetTempFileName() + ".txt";
File.WriteAllText(tmpfile, input);
}
// Show the file in the default .txt editor.
startInfo = new ProcessStartInfo();
startInfo.Arguments = "";
startInfo.FileName = tmpfile;
startInfo.Verb = "Open";
startInfo.WorkingDirectory = Environment.CurrentDirectory;
p = Process.Start(startInfo);
if (optWait) {
p.WaitForExit(30000);
}
return 0;
}
private static void DisplayVersion( bool full )
{
FileVersionInfo fi = FileVersionInfo.GetVersionInfo(Assembly.GetEntryAssembly().Location);
if (full) {
Console.Out.WriteLine("{4} v{0}.{1}.{2}.{3}", fi.FileMajorPart, fi.FileMinorPart, fi.ProductBuildPart, fi.ProductPrivatePart, fi.OriginalFilename);
Console.Out.WriteLine(fi.LegalCopyright);
Console.Out.WriteLine("Saves its stdin to a temporary file and opens it in the default text editor.");
} else {
Console.Out.WriteLine("{0}.{1}.{2}.{3}", fi.FileMajorPart, fi.FileMinorPart, fi.ProductBuildPart, fi.ProductPrivatePart);
}
}
}
}