Created
September 2, 2011 19:46
-
-
Save SuperYeti/1189688 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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