Labfans是一个针对大学生、工程师和科研工作者的技术社区。 | 论坛首页 | 联系我们(Contact Us) |
![]() |
![]() |
#1 |
高级会员
注册日期: 2019-11-21
帖子: 3,006
声望力: 66 ![]() |
![]()
我的~/.inputrc有这些行:
set editing-mode vi set keymap vi 这使我可以在每个使用GNU readlines进行文本输入的程序中使用vi键绑定。示例: python , irb , sftp , bash , sqlite3等。它使使用命令行变得轻而易举。 Matlab 不使用readlines,但是在进行调试或交互工作时, vi按键绑定将是惊人的 。有没有现有的解决方案? 我倾向于使用matlab -nosplash -nodesktop命令行和让我思考:有可能写一个包装, 不使用readlines方法和输入传递到matlab ? (如果我必须实现这一点,我可能更愿意在Ruby中实现。) 更新: 谢谢您的帮助。这几乎可以工作: # See also: http://bogojoker.com/readline/ require 'readline' puts 'Starting Matlab...' io = IO.popen('matlab -nosplash -nodesktop 2>&1', 'w+') while input_line = Readline.readline('>> ', true) io.puts input_line puts io.gets end 但是它一次只从Matlab读取一行(因为我正在使用gets )。关于如何获取所有内容直到下一次等待输入的任何想法?这是正在发生的事情(我在>>提示符下输入内容): Starting Matlab... >> 1 >> 2 < MATLAB (R) > >> 3 Copyright 1984-2009 The MathWorks, Inc. >> 4 Version 7.8.0.347 (R2009a) 32-bit (glnx86) >> 5 February 12, 2009 >> 6 >> 7 >> 8 To get started, type one of these: helpwin, helpdesk, or demo. >> 9 For product information, visit www.mathworks.com. >> 0 >> 1 >> >> 2 ans = >> 3 >> 4 1 >> 5 >> 6 >> >> 7 ans = >> 8 >> 9 2 >> 0 >> 1 >> >> 2 ans = >> 3 >> 4 3 回答: 是的,那应该很容易。这只是一般“打开进程并绑定到其stdin和stdout”问题的特例,这并不困难。 谷歌的一些搜索发现IO.popen()是正确的Ruby,此处的答复中有更多详细信息: http : //groups.google.com/group/ruby-talk-google/ Browse_thread / thread / 0bbf0a3f1668184c 。希望这足以让您入门! 更新:看来您的包装即将到来。您需要完成的工作是在Matlab要求输入时识别出,然后仅要求用户输入。我建议尝试以下伪代码: while input_line = Readline.readline('>> ', true) io.puts input_line while ((output_line = io.gets) != '>> ') // Loop until we get a prompt. puts io.gets end end 这不太正确,因为在请求第一条输入行之前,您需要做一次内循环,但这应该可以为您提供想法。您可能还需要调整正在寻找的提示文本。 更新2:好的,因此我们还需要考虑以下事实:提示后没有EOL,因此io.gets将挂起。这是一个修订的版本,它使用了以下事实:您可以在Matlab提示符后添加空白行,而它只会给您另一个提示而无需执行任何操作。我重新安排了循环以使事情更清楚一些,尽管这意味着您现在必须添加逻辑来确定何时完成。 while [not done] // figure this out somehow io.puts blank_line // This will answer the first // prompt we get. while ((output_line = io.gets) != '>> ') // Loop until we get a prompt. puts io.gets // This won't hang, since the end // prompt will get the blank // line we just sent. input_line = Readline.readline('>> ', true) // Get something, feed it io.puts input_line // to the next prompt. output_line = io.gets // This will eat the prompt that corresponds to // the line we just fed in. end 更多&回答... |
![]() |
![]() |