Python Forum
write the password in the Terminal
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
write the password in the Terminal
#1
Dear sirs ,

I'm new with python , but i have some backgroud in programming ,
i want to automate some task at work ,i'm using python 3 with linux opensuse
i'm using the "os" library , but i cant do something :
Q : how to write the necessary password when the terminal (linux terminal) ask you to type it ?

Regards
Reply
#2
Perhaps you can use subprocess.
Here is an example from here
I'm on my windows box but can be edited for linux

import subprocess

p = subprocess.Popen(['dir'], shell=True, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
p.stdin.write(b'mypassword\n')
result = p.stdout.read()
print(result)
mohamed_touil likes this post
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#3
Thank You
Reply
#4
(Mar-16-2023, 08:50 AM)mohamed_touil Wrote: Q : how to write the necessary password when the terminal (linux terminal) ask you to type it ?

Sounds you want to use tools, which do not accept passwords from arguments. SSH is one of the examples.
Some people use expect. I don't like this technique because it relies on external tools and the language settings of your OS.

https://pexpect.readthedocs.io/en/stable/

For example, I prefer paramiko for ssh.
Other protocols like ftp, http are also supported by Python directly.

If it's a complete different tool, you want to run, you may find a Python implementation of this tool on pypi.
ndc85430 likes this post
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020