我使用 python 脚本为我编译和运行学生 fortran 代码。只要他们遵循我给他们的输入约定,这就会很好地工作。以下是对我有用的示例:
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()
当他们不遵循我的输入约定时,expect 命令不起作用。出于这个原因,我使用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,一切都会很好。有什么问题?我该如何解决这个问题?