优化代码:chcp 65001 start cmd /K adb disconnect ping -n 1 127.0.0.1>nul :: close wifi adb wait-for-device adb root adb wait-for-device adb shell "cmd wifi set-wifi-enabled disabled" :: open wifi adb shell "cmd wifi set-wifi-enabled enabled" :: start scan
时间: 2024-02-11 07:09:16 浏览: 102
以下是优化后的代码:
```
@echo off
chcp 65001
start cmd /K adb disconnect
ping -n 1 127.0.0.1>nul
:: Close wifi
adb wait-for-device
adb root
adb wait-for-device
adb shell "cmd wifi set-wifi-enabled disabled"
:: Open wifi
adb shell "cmd wifi set-wifi-enabled enabled"
:: Start scan
adb shell "cmd wifi scan"
```
优化说明:
1. 去掉了注释,使代码更简洁易读。
2. 在开头加上了 `@echo off` 命令,可以关闭命令行窗口中的回显,使输出更干净整洁。
3. 将所有命令放在了一个批处理文件中,方便一次性执行。
4. 将 `adb disconnect` 命令的执行放在了新命令窗口中,避免出现在当前命令窗口中执行时会关闭连接的问题。
5. 将 `adb shell "cmd wifi scan"` 命令添加上,可以让扫描开始。
相关问题
D:\vbcentos7>chcp Active code page: 65001 D:\vbcentos7>vagrant init centos/7 Traceback (most recent call last): 8: from D:/program/vagrant/embedded/gems/2.2.18/gems/vagrant-2.2.18/bin/vagrant:194:in `<main>' 7: from D:/program/vagrant/embedded/gems/2.2.18/gems/vagrant-2.2.18/bin/vagrant:194:in `new' 6: from D:/program/vagrant/embedded/gems/2.2.18/gems/vagrant-2.2.18/lib/vagrant/environment.rb:124:in `initialize' 5: from D:/program/vagrant/embedded/gems/2.2.18/gems/vagrant-2.2.18/lib/vagrant/util/platform.rb:271:in `fs_real_path' 4: from D:/program/vagrant/embedded/gems/2.2.18/gems/vagrant-2.2.18/lib/vagrant/util/platform.rb:271:in `each' 3: from D:/program/vagrant/embedded/gems/2.2.18/gems/vagrant-2.2.18/lib/vagrant/util/platform.rb:272:in `block in fs_real_path' 2: from D:/program/vagrant/embedded/gems/2.2.18/gems/vagrant-2.2.18/lib/vagrant/util/platform.rb:272:in `each' 1: from D:/program/vagrant/embedded/gems/2.2.18/gems/vagrant-2.2.18/lib/vagrant/util/platform.rb:274:in `block (2 levels) in fs_real_path' D:/program/vagrant/embedded/gems/2.2.18/gems/vagrant-2.2.18/lib/vagrant/util/platform.rb:274:in `encode': "\\xE5" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to GBK (Encoding::UndefinedConversionError) 该怎么解决
这个错误是由于 Vagrant 在执行 init 命令时无法将路径转换为 UTF-8 编码。解决方法是设置系统环境变量 VAGRANT_DETECTED_OS 为 "cygwin",具体步骤如下:
1. 右键点击“此电脑”,选择“属性”。
2. 点击“高级系统设置”。
3. 点击“环境变量”。
4. 在“系统变量”中找到“VAGRANT_DETECTED_OS”,如果没有则点击“新建”,输入“VAGRANT_DETECTED_OS”为变量名,"cygwin"为变量值,然后点击“确定”即可。
5. 重新打开命令行窗口,执行 vagrant init 命令即可。
希望对你有所帮助!
这个问题该怎么解决Active code page: 65001 C:\Windows\System32>cd d/ d:vbcentos7 The system cannot find the path specified. C:\Windows\System32>cd d/ d:vbcentos7/ The system cannot find the path specified. C:\Windows\System32>cd /d D:\vbcentos7 D:\vbcentos7>vagrant up Traceback (most recent call last): 8: from D:/program/vagrant/embedded/gems/2.2.18/gems/vagrant-2.2.18/bin/vagrant:194:in `<main>' 7: from D:/program/vagrant/embedded/gems/2.2.18/gems/vagrant-2.2.18/bin/vagrant:194:in `new' 6: from D:/program/vagrant/embedded/gems/2.2.18/gems/vagrant-2.2.18/lib/vagrant/environment.rb:124:in `initialize' 5: from D:/program/vagrant/embedded/gems/2.2.18/gems/vagrant-2.2.18/lib/vagrant/util/platform.rb:271:in `fs_real_path' 4: from D:/program/vagrant/embedded/gems/2.2.18/gems/vagrant-2.2.18/lib/vagrant/util/platform.rb:271:in `each' 3: from D:/program/vagrant/embedded/gems/2.2.18/gems/vagrant-2.2.18/lib/vagrant/util/platform.rb:272:in `block in fs_real_path' 2: from D:/program/vagrant/embedded/gems/2.2.18/gems/vagrant-2.2.18/lib/vagrant/util/platform.rb:272:in `each' 1: from D:/program/vagrant/embedded/gems/2.2.18/gems/vagrant-2.2.18/lib/vagrant/util/platform.rb:274:in `block (2 levels) in fs_real_path' D:/program/vagrant/embedded/gems/2.2.18/gems/vagrant-2.2.18/lib/vagrant/util/platform.rb:274:in `encode': "\\xE5" to UTF-8 in conversion from ASCII-8BIT to UTF-8 to GBK (Encoding::UndefinedConversionError)
这个错误可能是因为你的文件路径中包含非 ASCII 字符,而 Vagrant 在处理路径时出现了编码格式不兼容的问题。为了解决这个问题,你可以尝试以下几种方法:
1. 将文件路径中的非 ASCII 字符替换为 ASCII 字符,例如将中文字符转换为拼音。这样可以避免 Vagrant 处理路径时出现编码格式不兼容的问题。
2. 将命令提示符的默认编码格式修改为 UTF-8。使用 `chcp 65001` 命令可以将命令提示符的默认编码格式修改为 UTF-8。这样 Vagrant 在处理路径时就可以使用 UTF-8 编码格式,避免了编码格式不兼容的问题。
3. 在代码中将文件路径转换为 UTF-8 编码格式。例如,你可以使用 `encode` 方法将文件路径从 GBK 编码格式转换为 UTF-8 编码格式,例如:
```
path = "D:/vbcentos7/虚拟机"
path = path.encode("UTF-8")
```
然后在调用 Vagrant 相关命令时使用这个已经转换为 UTF-8 编码格式的路径。
通过以上方法,你应该能够解决 Vagrant 处理路径时出现编码格式不兼容的问题。
阅读全文