Home > Enterprise >  system() takes at most 1 argument (2 given), trying to pass argument from user
system() takes at most 1 argument (2 given), trying to pass argument from user

Time:06-21

    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)

When someone writes the name, it does not print it, it prints user and I try to make

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

but its show me this erorr

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

CodePudding user response:

Don't use os.system(); use subprocess.call() instead.

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

CodePudding user response:

If you run the following, you are not passing the user variable to your command.

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

The following will not work as per the error you got, os.system() takes a single argument.

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

You can do the following, but you really should not as it allows code injection.

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

Plus you can read the following from the documentation ofos.system().

The subprocess module provides more powerful facilities for spawning new processes and retrieving their results; using that module is preferable to using this function. See the Replacing Older Functions with the subprocess Module section in the subprocess documentation for some helpful recipes.

So, instead you can use the following (credits to Charles Duffy):

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

Which is your command split by shlex.split() with a safe user variable passed and run by subprocess.call().

  • Related