LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-22-2011, 09:05 AM   #1
BrandonShw
LQ Newbie
 
Registered: Jun 2011
Posts: 11

Rep: Reputation: Disabled
Running an Interactive Program From Within a Program


I am trying to write a C or C++ program to control a telnet session. For the purpose of this question we could simplify the issue by assuming that I am relaying questions and answers to a user at the console. That's a simplification, but close enough.

I started out by opening a socket to the telnet port 23. I soon discovered that the handshake is complicated and there is no good documentation on what I have to do to satisfy the thing. Please don't tell me to read the telnet RFC because I did and it is the furthest thing imaginable from instructions on the negotiation.

Next I checked into the possibility that cURL could handle it, but there is nothing approaching actual instructions on how to write such a program and when I type cURL telnet://xxx.xxx.xxx.xxx to see if at least I can do it interactively, it fails to relay things to and from the screen properly and freezes a lot.

Next, I checked into using popen, but I soon became convinced that I would need two pipes and simply don't know how to do it. I can control programs I write with a pair of pipes, but I am trying to control the telnet app that comes with Linux and this would seem to involve stdin and stdout. There is undoubtedly a way to do it by taking over stdin and stdout, but I sure don't know how.

Next up was IPWorks by nsoftware, and they even have a Telnet class, but it is utterly undocumented except for a class reference, which would be very hard to write an app from.

I would be grateful for any help I could get with this. I have been writing code and Googling for a day. Thanks in advance.

Brandon
 
Old 11-22-2011, 04:44 PM   #2
kbp
Senior Member
 
Registered: Aug 2009
Posts: 3,790

Rep: Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653Reputation: 653
Expect ?
 
Old 11-23-2011, 06:02 AM   #3
BrandonShw
LQ Newbie
 
Registered: Jun 2011
Posts: 11

Original Poster
Rep: Reputation: Disabled
Doesn't Expect have some requirements for the users' computers, like Tcl or something? If so, I can't use it because this has to work on many user configurations.
 
Old 11-23-2011, 06:52 AM   #4
Nominal Animal
Senior Member
 
Registered: Dec 2010
Location: Finland
Distribution: Xubuntu, CentOS, LFS
Posts: 1,723
Blog Entries: 3

Rep: Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948Reputation: 948
Take a look at the PuTTY sources. It is distributed under the MIT license. (Like the page says, you can use the code however you like, even in proprietary software, as long as you show the copyright notice and the license text in the combined/derivative product.)
At a quick glance, it seems the telnet stuff is pretty well contained in putty-version/telnet.c file, although it is not exactly in library form.
 
Old 11-23-2011, 12:51 PM   #5
BrandonShw
LQ Newbie
 
Registered: Jun 2011
Posts: 11

Original Poster
Rep: Reputation: Disabled
Actually, I finally got the IPWorks Telnet class to work.

Also, I understand that I can run interactive programs from C in general by forking a child, connecting pipes to it, and then using one of the exec commands. That looks like a useful thing to know how to do, although I guess I have what I need in this case. I have seen some of the Putty code and the negotiation with the Telnet server is really ugly. As for simply calling Putty, I cannot ask users to have it on every box running this code. I appreciate the input, though.
 
  


Reply



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
Human Weight loss interactive program? 44139 Linux - Newbie 2 08-06-2010 04:55 PM
LXer: Teaching Math with the KDE Interactive Geometry Program LXer Syndicated Linux News 0 06-19-2009 07:40 PM
Running program from terminal with & does nothing, program stops DittoAlex Linux - General 1 10-05-2007 01:35 AM
Run interactive program in shell escargot22026 Programming 4 08-14-2004 11:59 PM
Command-driven interactive C++ program Y0jiMb0 Programming 11 01-13-2004 07:24 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:13 AM.

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
Open Source Consulting | Domain Registration