Brian
Brian

Reputation: 66

Python calling Perl Script

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.

Upvotes: 0

Views: 766

Answers (1)

Corey Goldberg
Corey Goldberg

Reputation: 60604

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

Upvotes: 3

Related Questions