-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathShellHelper.cs
33 lines (31 loc) · 943 Bytes
/
ShellHelper.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
using System.Diagnostics;
using System.Threading.Tasks;
namespace ExtractOcrApi
{
public static class ShellHelper
{
public async static Task<string> Bash(this string cmd)
{
var process = GetProcess(cmd);
process.Start();
string result = await process.StandardOutput.ReadToEndAsync();
process.WaitForExit();
return result;
}
private static Process GetProcess(string cmd)
{
var escapedArgs = cmd.Replace("\"", "\\\"");
return new Process()
{
StartInfo = new ProcessStartInfo
{
FileName = "/bin/bash",
Arguments = $"-c \"{escapedArgs}\"",
RedirectStandardOutput = true,
UseShellExecute = false,
CreateNoWindow = true,
}
};
}
}
}