pexpect “no such file or directory” for a bash command that works
Question
sCMD = 'ssh user@host cat some/path | grep "Oct 31\|Oct 30"'
child = pexpect.spawn(sCMD)
try:
child.expect("assword")
except pexpect.EOF:
raise Exception("Cannot connect to host")
child.sendline(ssh_pass)
lData = [s.strip(' \n\r:') for s in child.readlines()]
lData[0] reads "No such file or directory"
if I change the first line to read:
sCMD = 'ssh user@host cat some/path'
Then lData contains all the lines from the file.
But if I execute the exact same command (with the grep) in a terminal it works fine - it returns the text I expect. No complaints.
Any idea why the command performs differently when executed via pexpect?
Solution
sCMD = 'ssh user@host \'cat some/path | grep "Oct 31\|Oct 30"\''
for some reason pexpect requires those extra single quotes.
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow