I've a perfectly working expect script that I'm trying to convert to python using expect or subprocess. I've created it using autoexpect
.
It just wait for password prompt and ignore it by pressing Enter key:
set timeout -1
spawn ./electron-cash --dir "" create
match_max 100000
expect -exact "Password (hit return if you do not wish to encrypt your wallet):"
send -- "\r"
expect eof
However when I tried to do the same using pexpect
I had all different type of issues. Either it stuck with no response or just shows nothing and close.
Here is what I came up with but it hangs doing nothing:
import pexpect
import sys
python_exec = "/home/user/electron-cash-wallet/venv/bin/python"
command = "/home/user/electron-cash-wallet/src/Electron-Cash/electron-cash"
p = pexpect.spawn(python_exec, [command, "--scalenet", "create"])
# ~ p.logfile_read = sys.stdout.buffer
p.expect("Password (hit return if you do not wish to encrypt your wallet):")
p.sendline(b'\r')
p.expect(pexpect.EOF)
I'm using Python 3