Skip to content

Commit

Permalink
update cmd.py
Browse files Browse the repository at this point in the history
  • Loading branch information
mikigo committed Aug 19, 2024
1 parent f80c529 commit 511f089
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions youqu3/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,16 @@ def expect_run(
如果 return_code=True,返回 (stdout, return_code)
"""
import pexpect
return pexpect.run(
res = pexpect.run(
cmd,
events=events,
withexitstatus=return_code,
timeout=timeout
)
if return_code is False:
return res.decode("utf-8")
stdout, return_code = res
return stdout.decode("utf-8"), return_code

@classmethod
def sudo_run(
Expand Down Expand Up @@ -133,10 +137,9 @@ def sudo_run(
)
if return_code is False:
return res.lstrip("请输入密码●")
else:
res = list(res)
res[0] = res[0].lstrip("请输入密码●")
return res
res = list(res)
res[0] = res[0].lstrip("请输入密码●")
return res


class RemoteCmd:
Expand All @@ -153,10 +156,7 @@ def remote_run(self, cmd: str, return_code: bool = False, timeout: int = None):
return_code=return_code,
timeout=timeout
)
if return_code is False:
return res.decode("utf-8")
stdout, return_code = res
return stdout.decode("utf-8"), return_code
return res

def remote_sudo_run(self, cmd: str, workdir: str = None, return_code: bool = False):
wd = ""
Expand Down

0 comments on commit 511f089

Please sign in to comment.