mirror of
https://github.com/ElectronNET/Electron.NET.git
synced 2026-02-11 05:34:34 +00:00
38 lines
1.1 KiB
C#
38 lines
1.1 KiB
C#
using System;
|
|
using System.Diagnostics;
|
|
|
|
namespace ElectronNET.CLI
|
|
{
|
|
public class ProcessHelper
|
|
{
|
|
public static void CmdExecute(string command, string workingDirectoryPath, bool output = true, bool waitForExit = 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();
|
|
|
|
if(waitForExit)
|
|
{
|
|
cmd.WaitForExit();
|
|
}
|
|
|
|
if (output)
|
|
{
|
|
Console.WriteLine(cmd.StandardOutput.ReadToEnd());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|