0

I'm creating an app that copy files to android device. When I run via cmd or powershell, it shows a percentage of copied files, but when using the following code, those not redirect the output. I try to create a CMD process, an ADB process, powershell, nothing, only shows the output at the end of the precess.

folderToLoad = txtOBBFolder.Text;
                        process = new Process();
                        process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
                        process.StartInfo.FileName = AppDomain.CurrentDomain.BaseDirectory + @"\adb.exe";
                        process.StartInfo.Arguments = @"push " + folderToLoad + " /sdcard/Android/obb/" + Path.GetFileName(folderToLoad);
                        process.StartInfo.WorkingDirectory = AppDomain.CurrentDomain.BaseDirectory;
                        process.StartInfo.UseShellExecute = false;
                        process.StartInfo.CreateNoWindow = true;
                        process.StartInfo.RedirectStandardError = true;
                        process.StartInfo.RedirectStandardOutput = true;
                        process.StartInfo.RedirectStandardInput = false;
                        process.Start();
                        q = "";
                        while (!process.HasExited)
                        {
                            q += process.StandardOutput.ReadToEnd();
                            q += process.StandardError.ReadToEnd();
                            txtOutput.AppendText(q);
                        }

Any one as a better way to make this?

If the adb push takes a while, for the user, it seems that the program hang up, thats why I would like to show a progress bar for example, with the percentage that is being sent.

Paulo
  • 11
  • 1
  • Better use a library that directly sends adb commands to the the adb-server without executing adb executable (in the context of Xamarin). IMHO that would be a preferred way as you don't have to interpret console text output. – Robert Jan 30 '23 at 16:47
  • What would be that lib? I have made this winforms project, dunno what lib should I add/use to avoid this process method. – Paulo Jan 30 '23 at 17:36
  • You may try one of the following to see if you get different results: https://stackoverflow.com/a/71344930/10024425 or https://stackoverflow.com/a/71846819/10024425 – Tu deschizi eu inchid Feb 01 '23 at 04:34

0 Answers0