From e0bab009cff8255c714b5b4069cb7528880240b2 Mon Sep 17 00:00:00 2001 From: codematrixer Date: Thu, 12 Dec 2024 15:18:36 +0800 Subject: [PATCH] fix: Ensure the path is properly quoted for windows --- README.md | 19 ++++++++++--------- hmdriver2/hdc.py | 6 ++++-- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 45f505a..6383fd6 100644 --- a/README.md +++ b/README.md @@ -450,15 +450,6 @@ d.swipe_ext(SwipeDirection.DOWN) # 向下滑动 Notes: `swipe_ext`和`swipe`的区别在于swipe_ext可以指定滑动区域,并且可以指定滑动方向,更简洁灵活 -#### 输入 -```python -d.input_text(text) - -# eg. -d.input_text("adbcdfg") -``` -参数`x`, `y`表示输入的位置,`text`表示输入的文本 - #### 复杂手势 复杂手势就是手指按下`start`,移动`move`,暂停`pause`的集合,最后运行`action` @@ -492,6 +483,16 @@ d.click(x, y) ![Watch the gif](https://i.ibb.co/PC76PRD/gesture.gif) +#### 输入 +```python +d.input_text(text) + +# eg. +d.input_text("adbcdfg") +``` +参数`x`, `y`表示输入的位置,`text`表示输入的文本 + + ## 控件操作 ### 常规选择器 diff --git a/hmdriver2/hdc.py b/hmdriver2/hdc.py index ed53ee3..163bff8 100644 --- a/hmdriver2/hdc.py +++ b/hmdriver2/hdc.py @@ -29,7 +29,7 @@ def _execute_command(cmdargs: Union[str, List[str]]) -> CommandResult: error = error.decode('utf-8') exit_code = process.returncode - if 'error:' in output.lower() or '[fail]:' in output.lower(): + if 'error:' in output.lower() or '[fail]' in output.lower(): return CommandResult("", output, -1) return CommandResult(output, error, exit_code) @@ -111,7 +111,9 @@ def uninstall(self, bundlename: str): return result def install(self, apkpath: str): - quoted_path = shlex.quote(apkpath) + # Ensure the path is properly quoted for Windows + quoted_path = f'"{apkpath}"' + result = _execute_command(f"hdc -t {self.serial} install {quoted_path}") if result.exit_code != 0: raise HdcError("HDC install error", result.error)