Vergiss das mit den Alternativen doch. pexpect geht nämlich im interaktivem Modus von Python nicht. Ich habe das Programm jetzt noch wirklich in eine Datei geschrieben und es läuft.
Code: Alles auswählen
import pexpect
child = pexpect.spawn('sudo touch /home/thelittlebug/Desktop/pexpect.txt')
child.expect('Password:')
child.sendline('meinpw')
Als Ausgabe bekomme ich dieses
Code: Alles auswählen
thelittlebug@ubuntu:~/Desktop$ python test.py
Traceback (most recent call last):
File "test.py", line 4, in <module>
child.expect('Password:')
File "/usr/lib/python2.5/site-packages/pexpect.py", line 1064, in expect
return self.expect_list(compiled_pattern_list, timeout, searchwindowsize)
File "/usr/lib/python2.5/site-packages/pexpect.py", line 1132, in expect_list
raise EOF (str(e) + '\n' + str(self))
pexpect.EOF: End Of File (EOF) in read_nonblocking(). Exception style platform.
<pexpect.spawn object at 0xb7df1d8c>
version: 2.1 ($Revision: 395 $)
command: /usr/bin/sudo
args: ['/usr/bin/sudo', 'touch', '/home/thelittlebug/Desktop/pexpect.txt']
patterns:
Password:
buffer (last 100 chars):
before (last 100 chars):
after: <class 'pexpect.EOF'>
match: None
match_index: None
exitstatus: 0
flag_eof: True
pid: 5924
child_fd: 3
closed: False
timeout: 30
delimiter: <class 'pexpect.EOF'>
logfile: None
maxread: 2000
ignorecase: False
searchwindowsize: None
delaybeforesend: 0.1
delayafterclose: 0.1
delayafterterminate: 0.1
Ich hab echt keine Ahnung ob mir das Sorgen machen muss oder nicht.
Geht bei dir meine Version des Codes auch?
lgherby