Skip to content
Advertisement

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

JavaScript

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

JavaScript

but its show me this erorr

JavaScript

Advertisement

Answer

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

JavaScript

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

JavaScript

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

JavaScript

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):

JavaScript

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

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement