0

So when I run my Perl script on command line, it will ask for

User: (type name and press enter)

Password: (then it will ask for password and then I press enter) then I can run commands

So if you see, that is a sequence of steps

I know when you use the subproccess commands, I can call a script and have it run. But once Python runs the command, how do you continue to type in the user password after typing in user? When I ran it using "subprocess.call(command, shell=True)" Pycharm ask for "User:" and when I type it in, it freezes.

If possible, I want to configure python to put in my login info into the script and then run a command. I've done something like this in the past but it just ran the script and outputed the data. This perl script requires me to logon before I can output data which is where im having problems.

1

1 Answer 1

3

check out the pexpect module. It does exactly what you want, for example:

child = pexpect.spawn('perl foo.pl')
child.expect('User:')
child.sendline('my_username')
child.expect('Password:')
child.sendline('my_password')
Sign up to request clarification or add additional context in comments.

1 Comment

or output, status = pexpect.run('perl foo.pl', withexitstatus=1, events={'(?i)user:': 'my_username', '(?i)password:': 'my_password'})

Your Answer

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.