1
我使用python腳本爲我編譯和運行學生fortran代碼。只要他們遵循我給他們的輸入約定,這就行得通。這裏是什麼適合我的例子:pexpect.spawn.interact返回輸入/輸出錯誤
child = pexpect.spawn(os.path.join(os.path.dirname(file),name))
child.expect('')
child.sendline(input)
child.expect(pexpect.EOF)
self.r_output.append(child.before)
child.close()
當他們不按我的輸入慣例,預計命令不起作用。爲此,我使用child.interact()
。但每當文件終於結束,我得到:
Traceback (most recent call last):
File "./project.py", line 263, in <module>
main()
File "./project.py", line 45, in main
stud.tohtml(f)
File "./project.py", line 173, in tohtml
self.run("<br/>")
File "./project.py", line 140, in run
child.interact(chr(27))
File "/usr/lib/python2.7/dist-packages/pexpect.py", line 1492, in interact
self.__interact_copy(escape_character, input_filter, output_filter)
File "/usr/lib/python2.7/dist-packages/pexpect.py", line 1520, in __interact_copy
data = self.__interact_read(self.child_fd)
File "/usr/lib/python2.7/dist-packages/pexpect.py", line 1510, in __interact_read
return os.read(fd, 1000)
OSError: [Errno 5] Input/output error
如果我足夠快,以按ASCII 29之前結束,一切都很好。什麼可能是錯的?我如何解決這個問題?