[Java for Android App Development] OmarBizreh:
And here is C# Translation for the code:

------------------------------------------------------------------------------------------------

Global Variables

------------------------------------------------------------------------------------------------

private Process p = null;
private string AdbPath = Path.Combine(Path.GetTempPath(), "RegawMOD", "AndroidLib", "adb");

------------------------------------------------------------------------------------------------

Process Definition

------------------------------------------------------------------------------------------------

try
{
p = new Process();
ProcessStartInfo sInfo = new ProcessStartInfo("cmd");
sInfo.RedirectStandardOutput = true;
sInfo.RedirectStandardInput = true;
sInfo.CreateNoWindow = true;
sInfo.UseShellExecute = false;
sInfo.WindowStyle = ProcessWindowStyle.Hidden;
p.StartInfo = sInfo;
p.OutputDataReceived += p_OutputDataReceived;
p.EnableRaisingEvents = true;
p.Start();
p.BeginOutputReadLine();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error starting adb process", MessageBoxButton.OK, MessageBoxImage.Error);
}

------------------------------------------------------------------------------------------------

p_OutputDataReceived Definition

------------------------------------------------------------------------------------------------

void p_OutputDataReceived(object sender, DataReceivedEventArgs e)
{
string line = "";
try
{
if (!(line = e.Data).Trim().Length.Equals(0) && !line.Contains("/system/bin/getprop ro.board.platform"))
{
this.Dispatcher.BeginInvoke(new Action(() => txt.AppendText(line + "\n")));
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Error Reading Output", MessageBoxButton.OK, MessageBoxImage.Error);
}
}

------------------------------------------------------------------------------------------------

Passing command to our little adb process

------------------------------------------------------------------------------------------------

if (p != null)
{
p.StandardInput.WriteLine(AdbPath + " shell /system/bin/getprop ro.board.platform");
}

------------------------------------------------------------------------------------------------

Side Notes:

------------------------------------------------------------------------------------------------

Code above will result in active shell, it's a simulation for executing commands via CMD

What you need to do is the following:

Change "AdbPath" content to match the path of your adb executable.

"txt" is the Textbox that will show the output, put your own object.

Remove this line " !line.Contains("/system/bin/getprop ro.board.platform);" from "p_OutputDataReceived" to have an idea why I included it in the first place, it's not a must to have it but it will make output look nicer.

In the "Passing command to our little adb process" section, you can replace " shell /system ...etc" with your own object to make the app flexible and be able to execute any command the user type [example: .p.StandardInput.WriteLine(String.Join(" ", AdbPath , CommandTextBox.Text));]

This is almost the same code I execute in Droid Manager for the active shell, I just added few more lines to serve my active shell demands :)

My device is rooted, nevertheless it doesn't matter which language we are using, as long as we are executing the same command, then it should work with non rooted devices too just like OP says :)

I use AndroidLib that's why my Adb path points to AndroidLib's adb executable.

------------------------------------------------------------------------------------------------

Good luck :)

------------------------------------------------------------------------------------------------

Edit:

[MENTION=4694009]Dr.Alexander_Breen[/MENTION] Yes /system is read only and we can read the file, but if you read it like a text file you will have to break text apart to get the value and not key + value. and you will have to go line by line to reach the key you want, so by using "getprop" you will get the value without having to write extra lines of code to make the app show you value only. As for me I prefer it that way, no need to make the app execute more lines of code just to get a part of the string.