echo expect脚本是非确定性的

时间:2014-03-02 20:06:24

标签: expect

以下期望/代码对有时只能起作用:

  1. 简单的cpp echo程序:

     #include <iostream>
     #include <string>
    
     using namespace std;
    
     int main()
     {
        string buffer;
        while (1)
        {
            getline(cin, buffer, '\n');
            if (cin.eof())
                break;
            cout<<buffer<<endl;
        }
        return 0;
     }
    
  2. 期待剧本

    #!/usr/bin/expect
    
    spawn ./echo
    
    exp_internal 1
    
    set timeout 1
    
    send "a\n"
    expect {
        -re {^a\r\n$}
    }
    
  3. 成功匹配:

    spawn ./echo
    send: sending "a\n" to { exp6 }
    Gate keeper glob pattern for '^a\r\n$' is 'a
    '. Activating booster.
    
    expect: does "" (spawn_id exp6) match regular expression "^a\r\n$"? Gate "a\r\n"? gate=no
    a
    
    expect: does "a\r\n" (spawn_id exp6) match regular expression "^a\r\n$"? Gate "a\r\n"? gate=yes re=yes
    expect: set expect_out(0,string) "a\r\n"
    expect: set expect_out(spawn_id) "exp6"
    expect: set expect_out(buffer) "a\r\n"
    
  4. 失败匹配:

    spawn ./echo
    send: sending "a\n" to { exp6 }
    Gate keeper glob pattern for '^a\r\n$' is 'a
    '. Activating booster.
    
    expect: does "" (spawn_id exp6) match regular expression "^a\r\n$"? Gate "a\r\n" gate=no
    a
    a
    
    expect: does "a\r\na\r\n" (spawn_id exp6) match regular expression "^a\r\n$"? Gate "a\r\n"? gate=yes re=no
    expect: timed out
    
  5. 我不明白为什么在某些跑步中我得到双线“a”,有些跑步我得到单曲?我会假设期望挂钩产生的过程,以便发送将所有内容传递给stdin,期望从stdout获取所有内容。

    任何澄清都将不胜感激。

0 个答案:

没有答案