Skip to content

Instantly share code, notes, and snippets.

@SuperYeti
Created September 2, 2011 19:46
Show Gist options
  • Save SuperYeti/1189688 to your computer and use it in GitHub Desktop.
Save SuperYeti/1189688 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Text.RegularExpressions;
namespace adb
{
class Program
{
const string abdLocation = @"c:\Android\android-sdk\platform-tools\adb_real.exe";
static void Main(string[] args)
{
List<string> newArgs = new List<string>();
if (args.Length > 0)
{
if (args[0].ToLower() == "-s" && Regex.IsMatch(args[1], @":\d{1,5}"))
{
for (int i = 2; i < args.Length; i++)
{
newArgs.Add("\"" + args[i] + "\"");
}
}
else
{
foreach (var arg in args)
newArgs.Add("\"" + arg + "\"");
}
args = newArgs.ToArray();
}
// Start the child process.
Process p = new Process();
// Redirect the output stream of the child process.
p.StartInfo.UseShellExecute = false;
p.StartInfo.RedirectStandardOutput = true;
p.StartInfo.FileName = abdLocation;
p.StartInfo.Arguments = Regex.Replace(string.Join(" ", args), @":\d{1,5}", "");
p.Start();
// Do not wait for the child process to exit before
// reading to the end of its redirected stream.
// p.WaitForExit();
// Read the output stream first and then wait.
string output = p.StandardOutput.ReadToEnd();
p.WaitForExit();
Console.Write(output);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment