andrew_89
asked on
subprocess Popen
This is driving me crazy as I cant figure out why it wont work. I have this very simple logic that once I can get working, I will start building more complex pieces:
process = Popen(['scp -i keyfile' ,'localpath', 'user@device:/remotepath'] , stdout=PIPE, stderr=PIPE)
stdout, stderr = process.communicate()
no matter how many ways I try to use the -i flag for the indentity to use for scp I get this:
Traceback (most recent call last):
File "./test.cgi", line 11, in <module>
File "/usr/lib/python2.7/subpro cess.py", line 672, in __init__
errread, errwrite)
File "/usr/lib/python2.7/subpro cess.py", line 1213, in _execute_child
raise child_exception
OSError: [Errno 2] No such file or directory
If I run it without the -i flag, it works but I am prompted for password. If I run the exact same command (the scp portion for the Linux command line, it works fine... Is there some special way to deal with passing flags to the system binary being used with Popen?
I had used this same method way back and had working, but just cant seem to get it right here. Anyone have any pointers.
thanks
Andy
process = Popen(['scp -i keyfile' ,'localpath', 'user@device:/remotepath']
stdout, stderr = process.communicate()
no matter how many ways I try to use the -i flag for the indentity to use for scp I get this:
Traceback (most recent call last):
File "./test.cgi", line 11, in <module>
File "/usr/lib/python2.7/subpro
errread, errwrite)
File "/usr/lib/python2.7/subpro
raise child_exception
OSError: [Errno 2] No such file or directory
If I run it without the -i flag, it works but I am prompted for password. If I run the exact same command (the scp portion for the Linux command line, it works fine... Is there some special way to deal with passing flags to the system binary being used with Popen?
I had used this same method way back and had working, but just cant seem to get it right here. Anyone have any pointers.
thanks
Andy
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
thanks that gets rid of the error but now of course I still get password prompt. That will end up being another issue that I can debug separately.
andy
andy
Two ways of getting rid of the password:
- ssh-agent can store the ssh passwords for you, so you don't have to enter them multiple times.
just run ssh-agent
and ssh-add prior to running your script.
Alternatively your python script could prompt for the password.
and you could use Pexpect (under linux) to send the password to scp
For more details it's probably best to open a new question.
- ssh-agent can store the ssh passwords for you, so you don't have to enter them multiple times.
just run ssh-agent
and ssh-add prior to running your script.
Alternatively your python script could prompt for the password.
and you could use Pexpect (under linux) to send the password to scp
For more details it's probably best to open a new question.
Shouldn't you write:
process = Popen(['scp', '-i', 'keyfile' ,'localpath', 'user@device:/remotepath']
instead of:
process = Popen(['scp -i keyfile' ,'localpath', 'user@device:/remotepath']