C#
C# adb 이용하여 Shell 명령어 실행 하기
악마성
2020. 5. 28. 14:56
728x90
반응형
private void test()
{
// 스크린 캡쳐 테스트
string[] szCom = new string[] {@"shell screencap -p /sdcard/Pictures/Screenshots/"+s+".png",
@"pull /sdcard/Pictures/Screenshots/"+s+".png "+output_path+@"\"+s+".png"};
foreach (string sz in szCom)
{
string output = getDeviceInfo(sz);
}
}
private static string getDeviceInfo(string command)
{
ProcessStartInfo psInfo = new ProcessStartInfo();
psInfo.FileName = @"adb.exe"; //실행파일
psInfo.Arguments = command;
psInfo.UseShellExecute = false; //쉘 기능을 사용 하지 않는다.
psInfo.CreateNoWindow = true;
psInfo.RedirectStandardOutput = true; //표준 출력을 리다이렉트
Process p = Process.Start(psInfo); //어플리케이션 실행
p.WaitForExit();
string output = p.StandardOutput.ReadToEnd(); //표준 출력 읽어 잡기
output = output.Replace("\r\r\n", "\n"); //줄바꿈 코드의 수정
//txt_Output.Text = output;
string szTemp = output;
szTemp = szTemp.Replace("\r\r\n", "\n"); //줄바꿈 코드의 수정
return szTemp;
}
728x90
반응형