0

If I run adduser testuser from the terminal the command asks me some questions like for a password. But this code:

import os
a = os.system('useradd testuser')

exist with error code 0 (no problem there). But it don't asks any question. Why is that? And how can I work around it. I also tried subprocess which did the same thing.

Niclas Nilsson
  • 5,691
  • 3
  • 30
  • 43

2 Answers2

8

This is because adduser and useradd are two different programs. The former asks interactive questions, the latter doesn't. If you want the interactive prompts, call adduser, and use subprocess.call() to do so.

Sven Marnach
  • 574,206
  • 118
  • 941
  • 841
2

Do you mean it didn't finish, or did you not see the expected results.

Also, did you notice that you said "adduser" in the text of your question but "useradd" in the python code? You may have confused these two similar commands!

Thrill Science
  • 408
  • 4
  • 14