From 63253f2a4e0f1889bb5173e858bec659173b7826 Mon Sep 17 00:00:00 2001 From: Daniele Corsini Date: Sat, 20 Jun 2020 22:36:29 +0200 Subject: [PATCH] Fix check version Fix #3 --- .vscode/launch.json | 2 +- .../Corsinvest.ProxmoxVE.Pepper.csproj | 4 +- src/Corsinvest.ProxmoxVE.Pepper/Program.cs | 40 +++++++++++++------ 3 files changed, 30 insertions(+), 16 deletions(-) diff --git a/.vscode/launch.json b/.vscode/launch.json index 9e0ee61..1f45d09 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -10,7 +10,7 @@ "request": "launch", "preLaunchTask": "build", // If you have changed target frameworks, make sure to update the program path. - "program": "${workspaceFolder}/src/Corsinvest.ProxmoxVE.Pepper/bin/Debug/netcoreapp3.0/cv4pve-pepper.dll", + "program": "${workspaceFolder}/src/Corsinvest.ProxmoxVE.Pepper/bin/Debug/netcoreapp3.1/cv4pve-pepper.dll", "args": [], "cwd": "${workspaceFolder}/src/Corsinvest.ProxmoxVE.Pepper", // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console diff --git a/src/Corsinvest.ProxmoxVE.Pepper/Corsinvest.ProxmoxVE.Pepper.csproj b/src/Corsinvest.ProxmoxVE.Pepper/Corsinvest.ProxmoxVE.Pepper.csproj index 140f5df..e28b846 100644 --- a/src/Corsinvest.ProxmoxVE.Pepper/Corsinvest.ProxmoxVE.Pepper.csproj +++ b/src/Corsinvest.ProxmoxVE.Pepper/Corsinvest.ProxmoxVE.Pepper.csproj @@ -1,7 +1,7 @@ Exe - 1.2.1 + 1.3.0 netcoreapp3.1 cv4pve-pepper Corsinvest Srl @@ -19,6 +19,6 @@ - + \ No newline at end of file diff --git a/src/Corsinvest.ProxmoxVE.Pepper/Program.cs b/src/Corsinvest.ProxmoxVE.Pepper/Program.cs index f971c03..934b848 100644 --- a/src/Corsinvest.ProxmoxVE.Pepper/Program.cs +++ b/src/Corsinvest.ProxmoxVE.Pepper/Program.cs @@ -10,6 +10,7 @@ * Copyright (C) 2016 Corsinvest Srl GPLv3 and CEL */ +using System.Diagnostics; using System.IO; using Corsinvest.ProxmoxVE.Api.Extension.Helpers; using Corsinvest.ProxmoxVE.Api.Shell.Helpers; @@ -21,7 +22,7 @@ namespace Corsinvest.ProxmoxVE.Pepper { static int Main(string[] args) { - var app = ShellHelper.CreateConsoleApp("cv4pve-pepper", + var app = ShellHelper.CreateConsoleApp("cv4pve-pepper", "Launching SPICE on Proxmox VE"); var optVmId = app.VmIdOrNameOption().DependOn(app, CommandOptionExtension.HOST_OPTION_NAME); @@ -29,27 +30,40 @@ namespace Corsinvest.ProxmoxVE.Pepper "Executable SPICE client remote viewer", CommandOptionType.SingleValue) .DependOn(app, CommandOptionExtension.HOST_OPTION_NAME); + optRemoteViewer.Accepts().ExistingFile(); app.OnExecute(() => { var fileName = Path.GetTempFileName().Replace(".tmp", ".vv"); - var ret = SpiceHelper.CreateFileSpaceClient(app.ClientTryLogin(), - optVmId.Value(), - fileName); + var ret = SpiceHelper.CreateFileSpaceClient(app.ClientTryLogin(), optVmId.Value(), fileName); if (ret) { - var cmd = StringHelper.Quote(optRemoteViewer.Value()) + - " " + - StringHelper.Quote(fileName); - ret = ShellHelper.Execute(cmd, - true, - null, - app.Out, - app.DryRunIsActive(), - app.DebugIsActive()).ExitCode == 0; + var process = new Process + { + StartInfo = new ProcessStartInfo() + { + UseShellExecute = false, + CreateNoWindow = true, + RedirectStandardOutput = false, + FileName = StringHelper.Quote(optRemoteViewer.Value()), + Arguments = StringHelper.Quote(fileName) + } + }; + + if (app.DebugIsActive()) + { + app.Out.WriteLine($"Run FileName: {process.StartInfo.FileName}"); + app.Out.WriteLine($"Run Arguments: {process.StartInfo.Arguments}"); + } + + if (!app.DryRunIsActive()) + { + process.Start(); + ret = process.HasExited ? process.ExitCode == 0 : true; + } } return ret ? 0 : 1;