欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

python第三方庫subprocess執(zhí)行cmd同時(shí)輸入密碼獲取參數(shù)

 更新時(shí)間:2024年01月11日 11:46:27   作者:車載testing  
本文給大家介紹python subprocess執(zhí)行cmd同時(shí)輸入密碼獲取參數(shù),手動(dòng)輸入cmd命令,本文給大家逐一介紹這個(gè)命令的使用方法,感興趣的朋友跟隨小編一起看看吧

python subprocess執(zhí)行cmd同時(shí)輸入密碼獲取參數(shù)

一:手動(dòng)輸入cmd命令

我們?cè)賵?zhí)行命令時(shí)需要同時(shí)傳入密碼或其他參數(shù)的時(shí)候,我們可以使用

echo {password} | adb shell ls /log'

這個(gè)命令是一個(gè)組合的命令,涉及到 echo、管道 | 和 adb shell ls /log。下面我會(huì)逐一解釋每個(gè)部分:

1. echo {password}:

echo 是一個(gè)常用的命令行工具,用于輸出一個(gè)字符串或變量的內(nèi)容。
{password} 是一個(gè)占位符,通常代表要輸出的密碼。不過,請(qǐng)注意,直接在命令行中輸出密碼(尤其是使用 echo)是不安全的,因?yàn)檫@會(huì)將密碼暴露在命令歷史中,也可能被其他用戶在進(jìn)程列表中看到。

2. |:

管道操作符。它的作用是將前一個(gè)命令的輸出作為下一個(gè)命令的輸入。

3. adb shell ls /log:

adb 是 Android Debug Bridge 的縮寫,它是一個(gè)命令行工具,允許你與 Android 設(shè)備進(jìn)行通信。
shell 命令告訴 adb 在 Android 設(shè)備上執(zhí)行一個(gè) shell 命令。
ls /log 是一個(gè) shell 命令,用于列出 /log 目錄下的文件和目錄。在許多 Android 設(shè)備上,這是一個(gè)包含系統(tǒng)日志文件的目錄。
組合起來,這個(gè)命令的意圖是:輸出密碼,然后將這個(gè)輸出作為 adb shell ls /log 的輸入。但實(shí)際上,這個(gè)命令可能不會(huì)按照預(yù)期工作,因?yàn)?adb shell ls /log 不期望從管道接收密碼作為輸入。而且,如前所述,直接在命令行中輸出密碼是不安全的。

二. 萬能python三方庫subprocess

 def subprocess_run( cmd, cmd_input=None):
        """
        執(zhí)行 cmd 命令
        """
        if cmd_input is not None:
            # 創(chuàng)建子進(jìn)程并執(zhí)行命令
            p = subprocess.Popen(cmd, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True)
            input_context = '{}\n'.format(cmd_input).encode('utf-8')
            p.stdin.write(input_context)
            # 獲取命令執(zhí)行結(jié)果
            output, error = p.communicate()
            # 使用sub函數(shù)去除命令行返回的命令符
            clean_output = re.sub(r'\x1b\[.*?m', '', output.decode('utf-8'))
            return clean_output
    	 else:
            process = subprocess.Popen(cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
            stdout, stderr = process.communicate()
            return stdout.decode(), stderr.decode()

到此這篇關(guān)于python subprocess執(zhí)行cmd同時(shí)輸入密碼獲取參數(shù)的文章就介紹到這了,更多相關(guān)python subprocess執(zhí)行cmd內(nèi)容請(qǐng)搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

最新評(píng)論