How to read return value from expect

Help
Aravinda
2009-01-28
2013-05-02
  • Aravinda
    Aravinda
    2009-01-28

    Hi,

    I would like to know how to read the string from expect which my program prints.

    I have a C program which prints a message using printf. How to capture this message using expect script.

    Please suggest me
    Aravinda

     
    • ender
      ender
      2009-01-28

      If you are running you're program with expect then in you're expect statement you could have it look for your output if it's somewhat static or use a regular expression. Then the value would be stored in the expect out buffer and you can put that into a variable.

       
    • ender
      ender
      2009-01-28

      If you are running you're program with expect then in you're expect statement you could have it look for your output if it's somewhat static or use a regular expression. Then the value would be stored in the expect out buffer and you can put that into a variable.

       
    • Aravinda
      Aravinda
      2009-01-29

      My program is like this. The test01 prints message using printf which I am not able to capture. Please give me an example, which would be very much help full.

      #!/usr/bin/expect
      catch {exec ./test01}
      set timeout 5
      expect "PASS"  { send "Test case is PASS\n" } \      "FAIL"  { send "Test Failed\n" } \      timeout  { send "No message\nbye\n" }

      Thanks.
      Aravinda

       
    • ender
      ender
      2009-01-29

      Instead of using exec try spawn. expect interacts with spawned processes. exec and system run commands outside of that.

      spawn /test01