Register
It is currently Sat Oct 25, 2014 11:58 pm

Problem with read


All times are UTC - 6 hours


Post new topic Reply to topic  [ 4 posts ] 
Author Message
 PostPosted: Wed May 26, 2010 2:42 pm   

Joined: Wed May 26, 2010 2:28 pm
Posts: 3
Hi,

I'm progaming a client/server using netcat

On the client :
Code:
echo $1 | netcat $2 $3


On the server :
Code:
read var
if [ "$var" = "xx" ]
then
      while [ ! "$choice" = "quit" ]
      do
            echo "1"
            read choice
            echo "2"
      done
fi


The problem is that "1" is printed to the screen but not the "2".
In fact, when my script run the read command I can write on the screen but the script never continu.

If someone could help me.

PS : sorry for my bad english !


Top
 Profile  
 PostPosted: Wed May 26, 2010 4:56 pm   
User avatar

Joined: Tue Apr 27, 2010 2:28 pm
Posts: 172
Location: Czech Republic
In the server code, there is no redirection. The read is therefore reading standard input, I fear. :-/


Top
 Profile  
 PostPosted: Wed May 26, 2010 11:52 pm   

Joined: Wed May 26, 2010 2:28 pm
Posts: 3
thanks for your answer but why the "2" is not printed ?


Top
 Profile  
 PostPosted: Thu May 27, 2010 9:18 am   

Joined: Wed May 26, 2010 2:28 pm
Posts: 3
Maybe, my explanation of the problem was not clear :

I'm progaming a client/server using netcat

On the server :
Code:
read var
        if [ "$var" = "xx" ]
        then
              while [ ! "$choice" = "quit" ]
              do
                    echo "1"
                    read choice
                    echo "2"
              done
        fi


I start the server and after I do : echo "xx" | netcat localhost 10000

The fisrt read is done and receive the "xx" from the echo. After, I have a problem because the standard input has been set to the echo and I would like that "read choice" read what is written throught the keyboard.

The problem is that the "1" is printed to the screen but the "2" is never printed because the second read waits for someting from the echo.

if someone could help me...


Top
 Profile  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: Google [Bot] and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
cron


BashScripts | Promote Your Page Too
Powered by phpBB © 2011 phpBB Group
© 2003 - 2011 USA LINUX USERS GROUP