PowerShell 中的 adb pull 命令有效但抛出异常
adb pull command in PowerShell works but throws an exception
当我在 PowerShell 中使用 adb pull 命令将文件从设备复制到 PC 时,我得到:
PS>.\adb.exe pull '/sdcard/temp/screenshot.png'
.\adb.exe : 6040 KB/s (34027 bytes in 0.005s)
At line:1 char:1
+ .\adb.exe pull '/sdcard/temp/screenshot.png'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (6040 KB/s (34027 bytes in 0.005s):String) [
], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
虽然实际上是复制了文件。
问题是我想在循环中使用它,所以当它抛出异常时,脚本停止播放。
cmd 中的相同命令完美运行。
exe 向错误流发送信息是很常见的。我相信这也是您在这里看到的。 "error"(读起来就像我用手指引号一样)很可能来自这一行
.\adb.exe : 6040 KB/s (34027 bytes in 0.005s)
如果您熟悉 psexec,错误信息流上会显示初始信息。
由于该数据位于错误流中,因此 PowerShell 会这样报告它。正如您在注释中所做的那样,将错误流重定向到 null 是可以接受的处理方法。 2>$null
如果您不需要返回输出,您也可以尝试使用 Start-Process
。
Start-Process adb.exe -ArgumentList "pull '/sdcard/temp/screenshot.png'"
如果在任何一种情况下确实存在错误,您只需要小心。
当我在 PowerShell 中使用 adb pull 命令将文件从设备复制到 PC 时,我得到:
PS>.\adb.exe pull '/sdcard/temp/screenshot.png'
.\adb.exe : 6040 KB/s (34027 bytes in 0.005s)
At line:1 char:1
+ .\adb.exe pull '/sdcard/temp/screenshot.png'
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (6040 KB/s (34027 bytes in 0.005s):String) [
], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
虽然实际上是复制了文件。
问题是我想在循环中使用它,所以当它抛出异常时,脚本停止播放。
cmd 中的相同命令完美运行。
exe 向错误流发送信息是很常见的。我相信这也是您在这里看到的。 "error"(读起来就像我用手指引号一样)很可能来自这一行
.\adb.exe : 6040 KB/s (34027 bytes in 0.005s)
如果您熟悉 psexec,错误信息流上会显示初始信息。
由于该数据位于错误流中,因此 PowerShell 会这样报告它。正如您在注释中所做的那样,将错误流重定向到 null 是可以接受的处理方法。 2>$null
如果您不需要返回输出,您也可以尝试使用 Start-Process
。
Start-Process adb.exe -ArgumentList "pull '/sdcard/temp/screenshot.png'"
如果在任何一种情况下确实存在错误,您只需要小心。