Welcome to the most active Linux Forum on the web.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
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!


  Search this Thread
Old 06-08-2015, 01:45 AM   #1
LQ Newbie
Registered: Jun 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
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
set id $spawn_id
interact {
        -input $id -output $user_spawn_id
        -input $id "add" {
        send -i $id "add\r"
        -input $id1 -output $id
        -input $id -output $user_spawn_id
        -input $id "sub" {
        send -i $id "sub\r"
        -input $id2 -output $id
        -input $id -output $user_spawn_id
        -input $id "mul" {
        send -i $id "mul\r"
        -input $id3 -output $id
        -input $id -output $user_spawn_id
        -input $id "div" {
        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..


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 10:16 PM
Redirect output sound to input (mic or line-in) chabacha Linux - Software 1 01-22-2011 03:15 PM
Redirect output sound to input (mic or line-in) chabacha Debian 1 01-22-2011 08:51 AM
bash input/output redirect problem greno Programming 2 12-31-2006 04:23 PM
Redirect /dev/ttyS0 input/output to tty2 Kymbo Linux - General 1 09-07-2006 11:07 AM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 05:37 AM.

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