Skip to content

Instantly share code, notes, and snippets.

@bozhink
Last active February 24, 2023 04:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bozhink/ced9e43eb51b11a84f853a497314822c to your computer and use it in GitHub Desktop.
Save bozhink/ced9e43eb51b11a84f853a497314822c to your computer and use it in GitHub Desktop.
Execute process in C# without console
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