-
Notifications
You must be signed in to change notification settings - Fork 21
/
Shell.cs
43 lines (38 loc) · 1.07 KB
/
Shell.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
using System.Diagnostics;
namespace WinHaste
{
// https://stackoverflow.com/questions/44205260/net-core-copy-to-clipboard
public static class Shell
{
public static string Bash(this string cmd)
{
var escapedArgs = cmd.Replace("\"", "\\\"");
string result = Run("/bin/bash", $"-c \"{escapedArgs}\"");
return result;
}
public static string Bat(this string cmd)
{
var escapedArgs = cmd.Replace("\"", "\\\"");
string result = Run("cmd.exe", $"/c \"{escapedArgs}\"");
return result;
}
private static string Run(string filename, string arguments)
{
var process = new Process
{
StartInfo = new ProcessStartInfo
{
FileName = filename,
Arguments = arguments,
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = false,
}
};
process.Start();
string result = process.StandardOutput.ReadToEnd();
process.WaitForExit();
return result;
}
}
}