LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-08-2015, 12:45 AM   #1
raul1rnjn535_3
LQ Newbie
 
Registered: May 2015
Location: India
Posts: 1

Rep: Reputation: Disabled
Redirect input/output from python to expect


I am working on a project where I am invoking a python script from an Expect script. The python script runs a CLI. I want to change the default behavior of "print" statement to send some string to the Expect script instead of sending it to terminal so that I can perform tasks based on the to be printed string.
1)Is it possible?
Currently I am using the following Expect script
Code:
spawn -noecho ./add.exp
set id1 $spawn_id
spawn -noecho ./sub.exp
set id2 $spawn_id
spawn -noecho ./mul.exp
set id3 $spawn_id
spawn -noecho ./div.exp
set id4 $spawn_id
spawn -noecho python cli.py
set id $spawn_id
interact {
        -input $id -output $user_spawn_id
        -o
        -input $id "add" {
        return
        send -i $id "add\r"
        -input $id1 -output $id
        -input $id -output $user_spawn_id
        }
        -input $id "sub" {
        return
        send -i $id "sub\r"
        -input $id2 -output $id
        -input $id -output $user_spawn_id
        }
        -input $id "mul" {
        return
        send -i $id "mul\r"
        -input $id3 -output $id
        -input $id -output $user_spawn_id
        }
        -input $id "div" {
        return
        send -i $id "div\r"
        -input $id4 -output $id
        -input $id -output $user_spawn_id
        }
        -input $id -output $user_spawn_id
        -input $user_spawn_id -output $id
}
In the python script I am simply printing the "add" string.

2)If not possible then how can I achieve the above mentioned task?

3)Since I am new to Expect there can be some mistake in my code.

Please help me..
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
how to redirect input and output to one file dspjm Linux - Software 1 12-08-2012 09:16 PM
Redirect output sound to input (mic or line-in) chabacha Linux - Software 1 01-22-2011 02:15 PM
Redirect output sound to input (mic or line-in) chabacha Debian 1 01-22-2011 07:51 AM
bash input/output redirect problem greno Programming 2 12-31-2006 03:23 PM
Redirect /dev/ttyS0 input/output to tty2 Kymbo Linux - General 1 09-07-2006 10:07 AM


All times are GMT -5. The time now is 11:35 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration