1

I'm facing some problems with adb commands pull/push.

Sometimes, the command work well, I launch it, I get the percent and the result at the end :) . Like this :

enter image description here enter image description here

But sometimes the command doesn't return anything until it's finished. So instead of getting the progress I get nothing but an empty line :/

enter image description here

And the result at the end

enter image description here

Of course, both behaviors are obtained with exactly the same environment. Same device, same powershell window, same cable... But with an interval of 5 minutes...

I tried to reproduce the behavior many times, by changing the usb connection type of the device, killing and restarting the adb server, unplugging and replugging the device, changing adb server port, checking TCP connexion, use another command line tool... But I never found anything tangible

My final goal is to have a software that launches the pull/push and displays the progress during the process. Everything works fine, but obviously only when the adb command returns the right things

Is there some options that I'm missing ? Can I force the behavior ?

I'm using ADB version 31.0.3 and differents Android phone (Samsung/Huawei and Oppo)

Nanis
  • 361
  • 6
  • 18
  • 3
    Please do not post command-line output as screen shot. Your screen shot are so small that it is really difficult to read them. Instead copy and paste the command-line output as text into your question and format it as code. – Robert Jan 12 '22 at 16:48
  • You don't have to use adb client tools to push/pull files. There are libraries available for Java, Dot.Net and other platforms that directly communicate with the adb-server so you don't have to parse command-line output. – Robert Jan 12 '22 at 16:51
  • Thank's Robert, but I'm looking for a real solution, not a workaround. – Nanis Jan 17 '22 at 08:10
  • 3
    Using a command-line command and parsing it's output is what I would call a workaround compared to directly "speaking" the adb protocol. – Robert Jan 17 '22 at 08:12
  • I don't think you understood the problem. I run the command with C# using the Process class. Just like any library you recommend. I didn't write the code that does the job because I can reproduce the behavior outside of my software, so the problem isn't there. – Nanis Jan 17 '22 at 08:18
  • Sorry but you don't understand. the adb command just speaks to the adb server running on your system. So you can replace the adb command-line program by an adb library that speaks directly to the adb server. So there is no command-line output to parse and no indeterministic behavior. I remember that one library is maintained by Microsoft itself (for the Xamarin development environment). So this is the library MS uses for installing Xamarin apps via Visual Studio as well as up/download files. – Robert Jan 17 '22 at 08:22
  • Thanks for your point of view, but that's not what I want. This is not suitable for my software – Nanis Jan 17 '22 at 08:37
  • Sorry but I am a bit confused, a library that works deterministically is "not suitable" but a command-line program that has known problems is suitable? What are your requirements? – Robert Jan 17 '22 at 09:01
  • (part 1)I have already tried many libraries, including SharpAdbClient from Quamotion, which is the one that seemed to me the most serious.Beyond the fact that it also had random behaviors, it is no longer maintained and is therefore unusable for me. Now, this is clearly not the point of my question. I'm not looking for a library, I'm looking to understand these random behaviors I get with adb when I run a command. – Nanis Jan 17 '22 at 11:20
  • (part 2) Again, this behavior has nothing to do with the c# part of the project since it is reproduced in the classic command line.If you don't have an answer to the initial question, that's fine, but I don't want to get into a debate about the pros and cons of using an unmaintained third party library versus what I have. – Nanis Jan 17 '22 at 11:20
  • Coming back to your question: If you want to understand why adb some times shows a progress and sometimes not look at it's source code (but fixing this would mean a custom adb executable so you again end up in something like I recommended). I also recommend to test different shells to make sure the problem is adb and not some weird behavior in powershell. – Robert Jan 17 '22 at 12:06
  • @Nanis May it be that you accidentally clicked into the PowerShell window after you started your command and sometimes not? Clicking into the PowerShell window enters the so called "selection mode". This mode can stop the execution of a whole script. May be it also prevents the output of a continuous progress info. – stackprotector Jan 17 '22 at 12:14
  • 1
    Here you will find the answer when and how the progress is written: https://android.googlesource.com/platform/system/core/+/refs/heads/android10-c2f2-release/adb/client/file_sync_client.cpp – Robert Jan 17 '22 at 12:14
  • @stackprotector I've done it lot of times to be sure that I haven't done anything wrong – Nanis Jan 18 '22 at 07:58
  • @Robert Thx I will have a look, I don't think that I will recompile adb by my own but perhaps there is some answer in the code – Nanis Jan 18 '22 at 08:02

1 Answers1

0

This is interesting! For me, it's seems like the command you are executing should run as a background job e.g. - a task that may execute for a while and you wish to run in the background in order to avoid it to block your current session

Following this answer which direct us to the official documentation, it seems we need to do something like this:

$job = Start-Job adb pull -a "some_video-file.mp4"
Wait-Job $job
Receive-Job $job

It should wait until the job is completed (regardless to the overall files size, which in our case - impacts how long the operation will take) and only then return the output (signaling that the upload process is completed)

The only question remains - will it work? Please try this and share your findings with us. tnx

ymz
  • 6,602
  • 1
  • 20
  • 39