system()最多接受1个参数(给定2个),试图从用户传递参数


user = input("enter target account:")
if inp==1:
os.system("adb shell monkey -p com.instagram.android -v 1")
time.sleep(1)
os.system("adb shell input tap 328 2200")
time.sleep(1)
os.system("adb shell input tap 500 178")
time.sleep(1)
os.system("adb shell input text user")
time.sleep(1.5)

当有人写名字时,它不打印它,它打印user我试着让

os.system("adb shell input text", user)

但是它显示了这个错误

system() takes at most 1 argument (2 given)

如果您运行以下命令,您没有将user变量传递给您的命令。

os.system("adb shell input text user")

根据您得到的错误,以下将无法工作,os.system()接受单个参数。

os.system("adb shell input text", user)

你可以这样做,但是你真的不应该,因为它允许代码注入.

os.system(f"adb shell input text {user}")

另外,您可以从os.system()的文档中阅读以下内容。

subprocess模块为生成新进程和检索其结果提供了更强大的功能;使用那个模块比使用这个函数更可取。请参阅subprocess文档中的"用子进程模块替换旧函数"一节,以获得一些有用的方法。

所以,你可以使用下面的(感谢Charles Duffy):

subprocess.call(["adb", "shell", "input", "text", user])

这是你的命令分割由shlex.split()与一个安全的user变量传递和subprocess.call()运行。

不要使用os.system();用subprocess.call()代替。

subprocess.call(['adb', 'shell', 'input', 'text', user])

最新更新