when i write in adb:
adb shell dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp'
I get the error output:
'grep' is not recognized as an internal or external command, operable program or batch file.
but if I divided it into two operators:
adb shell
dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp'
it works fine (it gives the name of the main activity of the running application).
if the only way is to split it into two - these are meens that first go into the adb shell and then run the request, is there a way to do this from C #?
in my code, it only does the first part (shell input).
here is my code:
public static void startNewProccess(object startInfo)
{
p = new Process();
p.StartInfo = (System.Diagnostics.ProcessStartInfo)startInfo;
p.Start();
p.WaitForExit();
}
public static void getMainActivity()
{
var startInfo1 = new System.Diagnostics.ProcessStartInfo
{
WorkingDirectory = @ADB_FOLDER,
WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal,
FileName = "cmd.exe",
Arguments = "/c" + " adb shell",
UseShellExecute = false
};
startNewProccess(startInfo1);
var startInfo2 = new System.Diagnostics.ProcessStartInfo
{
WorkingDirectory = @ADB_FOLDER,
WindowStyle = System.Diagnostics.ProcessWindowStyle.Normal,
FileName = "cmd.exe",
Arguments = "/c" + " dumpsys window windows | grep -E 'mCurrentFocus|mFocusedApp'",
UseShellExecute = false
};
}
source
share