首页 > 解决方案 > 自动化 adb push 返回空变量

问题描述

我想制作一个批处理文件(或者 PowerShell,如果你更喜欢它,你可以选择。我的代码是一个批处理文件),以自动将文件传输到 Android 设备

因此,用户将被询问原始文件的位置和名称然后,用户被询问目的地的位置。然后,运行 adb push 命令

我的代码是:

set /p filename="What is the location and name of the file you want to transfer? > "
set /p location="What is the location you want to set it to? > "
set fullmsg=adb push '%filename%' '%loaction%'
echo %fullmsg%
#just echoing out, to make shure it's correct
pause

现在发生的是,它输出:

adb push 'file.txt' ''

所以,这个位置是空的。另外,如果文件名有撇号 (') 或类似的东西怎么办:那是 right.txt

当然,它需要用引号引起来,但如果你有这样的位置:\\mysharedfolder\text files\ #注意反斜杠以及单词 text 和 files 之间的空格

希望这个解释足够好,因为我不知道如何解释它。

提前致谢

标签: powershellbatch-file

解决方案


在 PowerShell 中:

$file = Read-Host 'What is the location and name of the file you want to transfer?'
$location = Read-Host 'What is the location you want to set it to?'
# Showing command about to be run
Write-Host "adb push $file $location"
# pausing before running command
pause
adb push $file $location

推荐阅读