Last active
February 24, 2023 04:30
-
-
Save bozhink/ced9e43eb51b11a84f853a497314822c to your computer and use it in GitHub Desktop.
Execute process in C# without console
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Diagnostics; | |
using System.Text; | |
public class Program | |
{ | |
public static void Main(string[] args) | |
{ | |
if (args.Length < 1) | |
{ | |
Console.WriteLine("{source} needed"); | |
Environment.Exit(1); | |
} | |
string sourceFile = args[0]; | |
var process = new Process | |
{ | |
EnableRaisingEvents = false, | |
StartInfo = new ProcessStartInfo | |
{ | |
FileName = @"C:\\Program Files\\7-Zip\\7z.exe", | |
CreateNoWindow = true, | |
WindowStyle = ProcessWindowStyle.Hidden, | |
Arguments = string.Format("x \"{0}\"", sourceFile), | |
WorkingDirectory = Environment.CurrentDirectory, | |
StandardErrorEncoding = Encoding.UTF8, | |
StandardOutputEncoding = Encoding.UTF8, | |
RedirectStandardError = true, | |
RedirectStandardInput = true, | |
RedirectStandardOutput = true, | |
UseShellExecute = false | |
} | |
}; | |
using (process) | |
{ | |
process.Start(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment