Skip to content

Commit c56d5a6

Browse files
author
Paul van Brenk
committed
Give usefull error when Nodejs exe is corrupt
1 parent 7d911a1 commit c56d5a6

File tree

1 file changed

+22
-8
lines changed

1 file changed

+22
-8
lines changed

Nodejs/Product/PressAnyKey/PressAnyKey.cs

Lines changed: 22 additions & 8 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,35 @@ 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 exc)
37+
{
38+
Console.WriteLine($"Failed to start process: '{exc.Message}'.");
39+
Console.WriteLine("Probable cause is the Nodejs exe is corrupt, please re-install.");
40+
exitCode = -1;
41+
}
2842

2943
if (args[0] == "both" ||
30-
(proc.ExitCode == 0 && args[0] == "normal") ||
31-
(proc.ExitCode != 0 && args[0] == "abnormal"))
44+
(exitCode == 0 && args[0] == "normal") ||
45+
(exitCode != 0 && args[0] == "abnormal"))
3246
{
3347
Console.Write("Press any key to continue...");
3448
Console.ReadKey();
3549
}
3650

37-
return proc.ExitCode;
51+
return exitCode;
3852
}
3953
}
4054
}

0 commit comments

Comments
 (0)