在 2019-05-31 21:51, Fc Zwtyds 写道:
在 2019-05-30 6:41, Cameron Simpson 写道:
...
...
...
The you could just use os.system() to run the other commands, because
the environment now has the necessary environment settings.
See how you go.
Cheers,
Cameron Simpson <c...@cskk.id.au> (formerly c...@zip.com.au)
Hi,
Under your guidance, the python code using ssh-agent ssh-add has been
running successfully. In addition to the code you wrote to me, I also
refer to man ssh-agent and subprocess: Subprocess management. I now know
the importance of environment variables.
This problem has puzzled me for nearly two weeks and solved this
problem with your help.
With your guidance and help, I have learned a lot. You are a very
good teacher. You are my teacher.
BTW, this program is for visit youtube.
Cheers!
Thanks so much.
import subprocess
import os
p = subprocess.Popen('ssh-agent -s', stdin = subprocess.PIPE, stdout =
subprocess.PIPE, stderr = subprocess.PIPE, shell = True,
universal_newlines = True)
outinfo, errinfo = p.communicate()
lines = outinfo.split('\n')
for line in lines[:-1]:
left, right = line.split(';', 1)
if '=' in left:
varname, varvalue = left.split('=', 1)
print(varname + "=" + varvalue)
os.environ[varname] = varvalue
os.system('ssh-add id_rsa')
os.system('ssh-add -l')
run ok!
--
https://mail.python.org/mailman/listinfo/python-list