Problem with an expect script using netcat under GNU/Linux

I am using expect under GNU/Linux. I am also using netcat (nc).
My problem is that when I run the following expect script it does not work. It never matches one of the choices in the expect list. I suspect that I cannot do what I want and hence the question to an expert. The problem may be with the fact that spawn is not able to synchronize with the command line I have issued. So far I have enabled debug and have seen that there is a problem with the parent being synchronized with the child.

Does anyone know of a way to do the equivalent and have it work with expect?

spawn echo "CMDTYPE" | nc dhcp66 17777
expect {
   "VIDEO"  { puts "video product" }
   "DATA"   { puts "data product" }
}

# this does work (example only)
spawn echo "VIDEO"
expect {
   "VIDEO"  { puts "video product" }
   "DATA"   { puts "data product" }
}
LVL 8
Anthony2000Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

 
ahoffmannCommented:
sounds like you're trying to connect to an ftp service
if that is the purpose you better use an ftp client instead of netcat
Also some ftp clients can be scripted by its own, without using expect.
0
 
Anthony2000Author Commented:
Its an application that accepts commands much like a command line interface.  I am planning to write my own simple version of netcat that sends a command and waits for a reply. I was hoping that I may have missed some other easy way (a simple tweak of my expect script).
0
 
Anthony2000Author Commented:
To fix ths problem, I created a special version of netcat that accepts as a commandline parameter the string to be sent. I used -T <text to send>
0

Experts Exchange Solution brought to you by ConnectWise

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
 
ahoffmannCommented:
agreed
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.