2

Hello i have such problem. I need to login via subprocess. So i want to create a input pipe and write login and password to them.So i try to do something like this:

sp = subprocess.Popen([cmd],stdout=subprocess.PIPE, stdin=subprocess.PIPE)
i, o = sp.communicate()

After first string i have such error tcgetattr: Inappropriate ioctl for device. And i have None value of o. How can i write smth to pipe in this case. Thank you for your help.

asked Dec 18, 2014 at 12:44
1
  • You're not providing anything for stderr: stderr=subprocess.PIPE Commented Dec 18, 2014 at 12:49

1 Answer 1

2

From subprocess.communicate(input) docs:

The optional input argument should be data to be sent to the child process ...
Note that if you want to send data to the process’s stdin, you need to create the Popen object with stdin=PIPE. Similarly, to get anything other than None in the result tuple, you need to give stdout=PIPE and/or stderr=PIPE too.

i.e., to pass input to the subprocess, specify input parameter; to get a non-None o value, you must specify stderr=PIPE.

In many case password prompt and password itself are not written to/read from a pipe but directly to/from terminal i.e., you might need a pseudo-tty to pass the password unless the command allows to set an option to accept password via stdin. You could use pexpect to interact with a child process using pty. See the first reason in Why not just use a pipe (popen())?

answered Dec 18, 2014 at 13:35
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.