|
1 | | -using System.Diagnostics; |
| 1 | +using System.Collections.Generic; |
| 2 | +using System.Diagnostics; |
2 | 3 | using System.IO; |
3 | 4 | using CommandLine; |
4 | 5 | using InEngine.Core.Exceptions; |
5 | 6 |
|
6 | 7 | namespace InEngine.Core.Commands |
7 | 8 | { |
8 | | - public class SystemProcess : AbstractCommand |
| 9 | + public class Exec : AbstractCommand |
9 | 10 | { |
10 | | - [Option('c', "command", Required = true, HelpText = "The name of the CLI program/command to run.")] |
11 | | - public string Command { get; set; } |
| 11 | + [Option('e', "executable", Required = true, HelpText = "The name of the CLI program/command to run.")] |
| 12 | + public string Executable { get; set; } |
12 | 13 |
|
13 | 14 | [Option('a', "args", HelpText = "Arguments for the CLI program/command.")] |
14 | 15 | public string Arguments { get; set; } |
15 | 16 |
|
16 | | - [Option('t', "timeout", DefaultValue = 900, HelpText = "The number of seconds to wait before killing the runnin process.")] |
| 17 | + [Option('t', "timeout", DefaultValue = 900, HelpText = "The number of seconds to wait before killing the running process.")] |
17 | 18 | public int Timeout { get; set; } |
18 | 19 |
|
| 20 | + public IDictionary<string, string> ExecWhitelist { get; set; } |
| 21 | + |
19 | 22 | public override void Run() |
20 | 23 | { |
21 | | - if (!File.Exists(Command)) |
22 | | - throw new CommandFailedException($"Cannot run {Command}. It either does not exist or is inaccessible. Exiting..."); |
| 24 | + if (ExecWhitelist == null) |
| 25 | + ExecWhitelist = InEngineSettings.Make().ExecWhitelist; |
| 26 | + if (!ExecWhitelist.ContainsKey(Executable)) |
| 27 | + throw new CommandFailedException("Executable is not whitelisted."); |
| 28 | + var fileName = ExecWhitelist[Executable]; |
| 29 | + if (!File.Exists(fileName)) |
| 30 | + throw new CommandFailedException($"Cannot run {fileName}. It either does not exist or is inaccessible. Exiting..."); |
23 | 31 | var process = new Process() { |
24 | | - StartInfo = new ProcessStartInfo(Command, Arguments) { |
| 32 | + StartInfo = new ProcessStartInfo(fileName, Arguments) { |
25 | 33 | UseShellExecute = false, |
26 | 34 | ErrorDialog = false, |
27 | 35 | RedirectStandardError = false, |
28 | 36 | RedirectStandardInput = false, |
29 | 37 | RedirectStandardOutput = false, |
30 | 38 | } |
31 | 39 | }; |
32 | | - var commandWithArguments = $"{Command} {Arguments}"; |
| 40 | + var commandWithArguments = $"{fileName} {Arguments}"; |
33 | 41 | process.Start(); |
34 | 42 | if (process.WaitForExit(Timeout * 1000)) { |
35 | 43 | return; |
|
0 commit comments