mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-08-11 02:29:41 +00:00
refactor implementation
This commit is contained in:
33
ElectronNET.CLI/ProcessHelper.cs
Normal file
33
ElectronNET.CLI/ProcessHelper.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace ElectronNET.CLI
|
||||
{
|
||||
public class ProcessHelper
|
||||
{
|
||||
public static void CmdExecute(string command, string workingDirectoryPath, bool output = true)
|
||||
{
|
||||
using (Process cmd = new Process())
|
||||
{
|
||||
cmd.StartInfo.FileName = "cmd.exe";
|
||||
cmd.StartInfo.RedirectStandardInput = true;
|
||||
cmd.StartInfo.RedirectStandardOutput = true;
|
||||
cmd.StartInfo.CreateNoWindow = true;
|
||||
cmd.StartInfo.UseShellExecute = false;
|
||||
cmd.StartInfo.WorkingDirectory = workingDirectoryPath;
|
||||
|
||||
cmd.Start();
|
||||
|
||||
cmd.StandardInput.WriteLine(command);
|
||||
cmd.StandardInput.Flush();
|
||||
cmd.StandardInput.Close();
|
||||
cmd.WaitForExit();
|
||||
|
||||
if (output)
|
||||
{
|
||||
Console.WriteLine(cmd.StandardOutput.ReadToEnd());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user