-
Notifications
You must be signed in to change notification settings - Fork 569
Expand file tree
/
Copy pathAdbHelper.cs
More file actions
32 lines (27 loc) · 1.04 KB
/
AdbHelper.cs
File metadata and controls
32 lines (27 loc) · 1.04 KB
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
using System.Diagnostics;
using Xamarin.Android.Tools;
static class AdbHelper
{
public static ProcessStartInfo CreateStartInfo (string adbPath, string? adbTarget, string arguments)
{
var fullArguments = string.IsNullOrEmpty (adbTarget) ? arguments : $"{adbTarget} {arguments}";
return new ProcessStartInfo {
FileName = adbPath,
Arguments = fullArguments,
UseShellExecute = false,
RedirectStandardOutput = true,
RedirectStandardError = true,
CreateNoWindow = true,
};
}
public static async Task<(int ExitCode, string Output, string Error)> RunAsync (string adbPath, string? adbTarget, string arguments, CancellationToken cancellationToken, bool verbose = false)
{
var psi = CreateStartInfo (adbPath, adbTarget, arguments);
if (verbose)
Console.WriteLine ($"Running: adb {psi.Arguments}");
using var stdout = new StringWriter ();
using var stderr = new StringWriter ();
var exitCode = await ProcessUtils.StartProcess (psi, stdout, stderr, cancellationToken);
return (exitCode, stdout.ToString (), stderr.ToString ());
}
}