Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 922
  • Last Modified:

sending stdin to a daemon telnet process??

I need to port an application from Unix to NT/2000.  On Unix, I have spawned a telnet application as a daemon process, and my applications can send information to it using  telnets process ID.  I want to be able to do the same within Windows.  There are two parts to this question:
     1) Within my application, how do I create a new process (running a console telnet application)  which will persist even after the spawning application dies?  I have a console version of telnet;  however, I do not actually need to see the console.  However, I need the telnet process to stay alive even after the spawning application dies so I can have other applications connect to it in the future.
     2) How can I send messages to that telnet process, and have that process receive them as if they were comming from stdin?  I believe I can redirect stdin if that would help.

please include sample code!

Thanks!

0
ivang061698
Asked:
ivang061698
  • 3
  • 2
1 Solution
 
NickRepinCommented:
1) Use just CreateProcess()

2)

INFO: Redirection Issues on Windows 95 MS-DOS Applications
http://support.microsoft.com/support/kb/articles/Q150/9/56.ASP

Q190351 - HOWTO: Spawn Console Processes with Redirected Standard Handles
http://support.microsoft.com/support/kb/articles/Q190/3/51.ASP
0
 
ivang061698Author Commented:
Thanks NickRepin, that's a good start.
There are two differences between what I need and what the HOWTO demonstrates.  Perhaps I can clarify what I need.  I have one application which will create the Telnet process.  This telnet process hopefully will stay alive even after the original application dies.  Then, when other applications are executed, and they want to send commands to this pre-existing Telnet session, they can connect to it and send the commands via redirected standard input.  In unix, you can do this by sending info via a process ID.

0
 
NickRepinCommented:
I see now. So Telnet is an existing application, which uses stdin, and you cannot change it?

I think the following should work:

You create a program which CreateNamedPipe() first, and then CreateProcess("Telnet",...DETACHED_PROCESS...). The named pipe handle must be passed to Telnet as described in the articles above. DETACHED_PROCESS might be used to hide Telnet from the user. The program can now exit. The named pipe must survive, because its handle is duplicated.

Now you can use CreateFile() and WriteFile() to connect and write to the named pipe from another process.

Note that you might need to redirect the stdout of Telnet as well.
0
 
NickRepinCommented:
did it help?
0
 
ivang061698Author Commented:
Yes.  Thanks for the tips!
0

Featured Post

Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now