Link to home
Start Free TrialLog in
Avatar of BrianGEFF719
BrianGEFF719Flag for United States of America

asked on

Redirect Console over Winsock

I was curious if anyone knew a way to redirect a console over winsock? I have a console based program that runs on Machine B. I would like to be able to telnet to Machine B from Machine A and have it like I am using the DOS window on MACHINE B.

If you need further explanation, let me know. I dont need a full example I know how to program I just need to know how to redirect the console so that it will display properly in telnet on the other side.


-Brian
Avatar of ennixo
ennixo
Flag of France image

you can get the command line's result with a > filename into the filename

example:
the client sends "dir", the server does :
dir > a.txt

then just open a.txt and send the content
to the client
Avatar of BrianGEFF719

ASKER

I cant do it like that, I need to have the program running and redirect whats going on with it. Its a DOS Program I use to manage a database on computer B and I need to be able to view the progress as if I am running the program on the computer.


-Brian
Avatar of jerry_jeremiah
jerry_jeremiah

Stdin and stdout are available as file handles.  This is a good thing, but if the program writes directly to the console's memory it may not go through stdout.  Is all the output going to stdout?

If so, then all you have to do is start the program the same way as a CGI program is started from a web server.  The socket server starts the program with the stdin and stdout as pipes then it can read from the socket and write to the stdin pipe, read from the stdout pipe and write to the socket.

For an example of how that might work, take a look at the source for any webserver that can do CGI (Apache comes to mind since the source is available)

I may try to put together an example...

Jerry
Does this program that converts the socket stuff into stdin and stdout have to be a VB program?  The question is in the VB section...  If it can be in C try the pipe() function in the standard library.  The Visual Studio help file even has an example for the pipe() function.

Jerry
ASKER CERTIFIED SOLUTION
Avatar of jerry_jeremiah
jerry_jeremiah

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Think of it like this...

Lets say I want to run FDISK over a network connection (hypothetical statement). I would want  to be able to telnet to the computer and have the computer run FDISK and redirect it back to the client so it can be displayed in a TELNET client.


-brian

Here is something else that will help you.

Assuming you can make a program that:
 - starts a command line program (fdisk, cmd, etc)
 - connects to the stdin and stdout
 - provides a socket server that allows telnet-type connections

Then you need some way of starting it remotely.  It has to be running on the remote machine, so you need some way to start it on that remote machine.

So, then I found something that could do that.  But it also does what you want (e.g. run fdisk remotely and display the results locally)  Check this out:

http://www.sysinternals.com/ntw2k/freeware/psexec.shtml

In general, the stuff at sysinternals.com is worth knowing about...

Jerry