> Hi Matt,  your first assumption was correct. I just want to write a C
> program
> that use a combination of fork and pipe to run "/usr/bin/telnet" and send
> and receive commands/data via telnet pipes. What I am after is I want to
> be able to create a two way pipes, telnet from a local UNIX machine
> to a remote Unix machine,  login, continue to keep the pipe open and
> excute some remote UNIX scripts or binary programs from remote machine.
> The output  comes back thru pipe.
> 
> I can not use perl or expect. My main program is already written in C.
> 
> Thanks in advance.

I rather think you're in for a tough time then; this does not work:
telnet <commandstorunthroughtelnet
because telnet does not read from stdin:

[summer@emu summer]$ telnet emu <telnetin
Trying 192.168.1.2...
Connected to emu.os2.ami.com.au.
Escape character is '^]'.
Connection closed by foreign host.
[summer@emu summer]$ cat telnetin
mailtest
tistmail
ls -l

[summer@emu summer]$ 

Consequently you can't do it easily with standard telnet.

Your main choices that I see are
1       Open a socket yourself to the target. You will need to implement some 
small part of the telnet protocol; RFCs describing it are legion.
2       Write an expect script (you din't say why you can't do this) and have it 
establish the connexion. you should be able to get to the point where all 
you have to do is talk to bash (or some other shell) at the other end 
through standard pipes. You can run the script via fork() and exec().
3       Talk to some other willing participant at the other end; perhaps rlogind 
or rshd, or some code of your own.

Before you ask again, review your question. We can help better if we know 
what you want to achieve as opposed to how you think you must it.


Here's roughly how I might do it using expect:
#!/usr/bin/expect --
spawn telnet remotebox
set timeout 60
expect "login: $"
sleep 1
send "user\r"
expect "Password: $"
send "secret\r"
expect "user"
interact
[summer@emu summer]$ 

I might then run that script from my C program, having first set its 
stdin, stderr and stdout.

-- 
Cheers
John Summerfield
http://os2.ami.com.au/os2/ for OS/2 support.
Configuration, networking, combined IBM ftpsites index.


-- 
To unsubscribe:
mail -s unsubscribe [EMAIL PROTECTED] < /dev/null

Reply via email to