我嘗試將 borgfs 掛載到目錄中。但是,此命令需要密碼,因此,我必須向 stdin 發送密碼。我在 Python 中找到了這個庫。但是,我無法掛載這個 fs。我哪里錯了?
./get.py
<pexpect.pty_spawn.spawn object at 0x7f26997c5100>
command: /usr/bin/borgfs
args: ['/usr/bin/borgfs', '/home/sincorchetes/work/esmerald', '/mnt/work/esmerald']
buffer (last 100 chars): b' for key /home/sincorchetes/work/esmerald: '
before (last 100 chars): ''
after: b'Enter passphrase'
match: <re.Match object; span=(0, 16), match=b'Enter passphrase'>
match_index: 0
exitstatus: None
flag_eof: False
pid: 913893
child_fd: 5
closed: False
timeout: 30
delimiter: <class 'pexpect.exceptions.EOF'>
logfile: None
logfile_read: None
logfile_send: None
maxread: 2000
ignorecase: False
searchwindowsize: None
delaybeforesend: 0.05
delayafterclose: 0.1
delayafterterminate: 0.1
這是腳本的代碼:
#!/mnt/aborg/bin/python
import pexpect
mypassword = "d6v6Q"
child = pexpect.spawn("borgfs /home/sincorchetes/work/esmerald /mnt/work/esmerald")
child.expect("Enter passphrase for key /home/sincorchetes/work/esmerald: ")
child.sendline(mypassword)
uj5u.com熱心網友回復:
我認為根據輸出,預期的 EOF 是這里的問題。您不期望登錄時出現 EOF,您期望登錄時出現密碼提示。
例如
$ Enter passphrase for key /home/sincorchetes/work/esmerald:
You enter password here ^
您在同一行的冒號后輸入密碼,而不是像這樣在下一行輸入密碼
$ Enter passphrase for key /home/sincorchetes/work/esmerald:
$
NOT here on the next line
將您的代碼更改為
# rest of the code
child.expect('Enter passphrase for key /home/sincorchetes/work/esmerald: ')
# Remove this line child.expect(pexpect.EOF)
child.sendline(mypassword)
uj5u.com熱心網友回復:
我可以看到發生了什么事child.interact()。我在 borg 中有一個以前的快取,我無法將此目錄安裝到推送y字中。
現在作業 100%。
代碼結果:
#!/mnt/aborg/bin/python
import pexpect
mypassword = "d6v6Q"
child = pexpect.spawn("borgfs /home/sincorchetes/work/esmerald /mnt/work/esmerald")
child.expect("Enter passphrase for key /home/sincorchetes/work/esmerald: ")
child.sendline(mypassword)
child.interact()
其余目錄作業正常(不需要 [y/N] 回復。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/323190.html
