1

Hey im trying to do a screenshot from "Mobilephone" from the terminal I can pull and push normally but when I use the command

.\adb exec-out screencap -p > ./pic3.png

The png cant open

ProAslan
  • 73
  • 10

2 Answers2

2

As of this writing (PowerShell 7.2.2), PowerShell's > operator is fundamentally incapable of capturing raw bytes (binary output) - see this answer for more information.

The simplest workaround is to call via cmd.exe, whose > operator does support raw byte streams:

cmd /c 'adb exec-out screencap -p > .\pic3.png'

The alternative is to save the screenshot directly to a file on the Android device (syntax gleaned from here), and download it afterwards, as you show in your own answer.

.\adb shell screencap ./pic3.png
mklement0
  • 382,024
  • 64
  • 607
  • 775
  • 1
    Yeah it works but in cmd without point before adb cmd /c db exec-out screencap -p > .\pic3.png' – ProAslan Apr 27 '22 at 12:52
  • Thanks for confirming, @ProAslan. As an aside: If `adb.exe` is located in the current directory, `.\adb` should work from `cmd.exe` too (but _not_ `./adb` with a _forward_ slash). In PowerShell, _both_ `.\adb` and `./adb` work, but _not_ `adb` (without a path), because PowerShell by security-minded design doesn't allow executing executables located in the current directory by name only. – mklement0 Apr 27 '22 at 14:08
1

Ok if I use

.\adb shell screencap ./pic3.png

in shell, then I can pull it with

.\adb pull sdcard/download/pic3.png
mklement0
  • 382,024
  • 64
  • 607
  • 775
ProAslan
  • 73
  • 10
  • I see - I missed that the command saves the screenshot to a file _on the Android device_. Please see my update, which shows a simpler alternative via `cmd /c` – mklement0 Apr 27 '22 at 07:36