Skip to content

Instantly share code, notes, and snippets.

@microhobby
Created September 17, 2019 00:20
Show Gist options
  • Save microhobby/552b1795fda1ad0ceab2720e5893558a to your computer and use it in GitHub Desktop.
Save microhobby/552b1795fda1ad0ceab2720e5893558a to your computer and use it in GitHub Desktop.
//
// Copyright (C) 2019 MicroHobby
//
// This program is free software: you can redistribute it and/or modify
// it under the +terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see http://www.gnu.org/licenses/.
//
// Author: matheus@castello.eng.br
//
using System;
using System.Diagnostics;
namespace Utils
{
public static class Cmd
{
public static string Bash(this string cmd)
{
var escapedArgs = cmd.Replace("\"", "\\\"");
var process = new Process()
{
StartInfo = new ProcessStartInfo
{
FileName = "/bin/bash",
Arguments = $"-c \"{escapedArgs}\"",
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true,
}
};
process.Start();
string result = process.StandardOutput.ReadToEnd();
process.WaitForExit();
return result;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment