Skip to content

Commit ae234e0

Browse files
authored
Merge pull request #1602 from paulvanbrenk/103gh
Give usefull error when Nodejs exe is corrupt
2 parents be36a42 + 8433e97 commit ae234e0

File tree

1 file changed

+37
-9
lines changed

1 file changed

+37
-9
lines changed

Nodejs/Product/PressAnyKey/PressAnyKey.cs

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
22

33
using System;
4+
using System.ComponentModel;
45
using System.Diagnostics;
56
using System.IO;
67
using System.Linq;
@@ -19,22 +20,49 @@ private static int Main(string[] args)
1920
}
2021

2122
Console.Title = args[2];
22-
var psi = new ProcessStartInfo(args[2], string.Join(" ", args.Skip(3).Select(arg => ProcessOutput.QuoteSingleArgument(arg))));
23-
psi.UseShellExecute = false;
23+
var psi = new ProcessStartInfo(args[2], string.Join(" ", args.Skip(3).Select(arg => ProcessOutput.QuoteSingleArgument(arg))))
24+
{
25+
UseShellExecute = false
26+
};
2427

25-
var proc = Process.Start(psi);
26-
File.WriteAllText(args[1], proc.Id.ToString());
27-
proc.WaitForExit();
28+
var exitCode = 0;
29+
try
30+
{
31+
var proc = Process.Start(psi);
32+
File.WriteAllText(args[1], proc.Id.ToString());
33+
proc.WaitForExit();
34+
exitCode = proc.ExitCode;
35+
}
36+
catch (Win32Exception)
37+
{
38+
Console.WriteLine("Failed to start process.");
39+
Console.WriteLine("Probable cause is the Node.js exe is corrupt, please re-install.");
40+
Console.WriteLine($"path: '{args[2]}'.");
41+
exitCode = -1;
42+
}
43+
44+
var shouldWait = true;
45+
46+
switch (args[0])
47+
{
48+
case "both":
49+
shouldWait = true;
50+
break;
51+
case "normal":
52+
shouldWait = exitCode == 0;
53+
break;
54+
case "abnormal":
55+
shouldWait = exitCode != 0;
56+
break;
57+
}
2858

29-
if (args[0] == "both" ||
30-
(proc.ExitCode == 0 && args[0] == "normal") ||
31-
(proc.ExitCode != 0 && args[0] == "abnormal"))
59+
if (shouldWait)
3260
{
3361
Console.Write("Press any key to continue...");
3462
Console.ReadKey();
3563
}
3664

37-
return proc.ExitCode;
65+
return exitCode;
3866
}
3967
}
4068
}

0 commit comments

Comments
 (0)