By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
449,018 Members | 870 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 449,018 IT Pros & Developers. It's quick & easy.

How to talk with an external console?

P: n/a
I have a full work app (server and client) that talk between two executables
trought Console.WriteLine(); & Console.ReadLine();

I have the source code of the server.

I need to make the client. To do this i have

Console.WriteLine("Hi server");

while (true)
{
String command = "";
try
{
command = Console.ReadLine();
if (command != null)
if(command.Length > 0)
System.Console.WriteLine("Server response: " + command);
}
catch (IOException ex)
{
Console.WriteLine(ex.StackTrace);
outWriter.WriteLine(ex.StackTrace);
}
}

But never can read anything.

I know good how to make a client server with TCP. But with Console appears
to be different.
When is "established" the connection?
Nov 16 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a

"~toki" <pedorro77.hotmail.com> wrote in message
news:ed**************@TK2MSFTNGP10.phx.gbl...
I have a full work app (server and client) that talk between two executables trought Console.WriteLine(); & Console.ReadLine(); .... But never can read anything.

I know good how to make a client server with TCP. But with Console appears
to be different.
When is "established" the connection?


As far as I know, different applications cannot communicate through a
console. Do you have some information indicating that they can?
Nov 16 '05 #2

P: n/a
I have the server source in C# and the client is an .exe (made in C)
I see how talk with a "debug windows" of the client.
The client send two tokens to the server.
And the server response with a token (that exists in the source code) with
Console.Write(returnToken);
It works fine.
I can't run the C# server from the MS IDE to stop and debug when the client
send the token.

*The client run the server when it start.

I have tried do it with System.Diagnostic.Process.Start("server.exe") but it
don't work.
"Michael A. Covington" <lo**@www.covingtoninnovations.com.for.address>
escribió en el mensaje news:ei**************@tk2msftngp13.phx.gbl...

"~toki" <pedorro77.hotmail.com> wrote in message
news:ed**************@TK2MSFTNGP10.phx.gbl...
I have a full work app (server and client) that talk between two

executables
trought Console.WriteLine(); & Console.ReadLine();

...
But never can read anything.

I know good how to make a client server with TCP. But with Console appears to be different.
When is "established" the connection?


As far as I know, different applications cannot communicate through a
console. Do you have some information indicating that they can?

Nov 16 '05 #3

P: n/a
Ah! Creo que lo que Ud. intenta es que quiere comunicar con otro proceso
por "standard input" y "standard output". No se' como se hace.

Anyone -- How do you get a process to read and write to another process's
stdin and stdout? If you can?
"~toki" <pedorro77.hotmail.com> wrote in message
news:uo**************@TK2MSFTNGP11.phx.gbl...
I have the server source in C# and the client is an .exe (made in C)
I see how talk with a "debug windows" of the client.
The client send two tokens to the server.
And the server response with a token (that exists in the source code) with
Console.Write(returnToken);
It works fine.
I can't run the C# server from the MS IDE to stop and debug when the client send the token.

*The client run the server when it start.

I have tried do it with System.Diagnostic.Process.Start("server.exe") but it don't work.
"Michael A. Covington" <lo**@www.covingtoninnovations.com.for.address>
escribió en el mensaje news:ei**************@tk2msftngp13.phx.gbl...

"~toki" <pedorro77.hotmail.com> wrote in message
news:ed**************@TK2MSFTNGP10.phx.gbl...
I have a full work app (server and client) that talk between two

executables
trought Console.WriteLine(); & Console.ReadLine();

...
But never can read anything.

I know good how to make a client server with TCP. But with Console appears to be different.
When is "established" the connection?


As far as I know, different applications cannot communicate through a
console. Do you have some information indicating that they can?


Nov 16 '05 #4

P: n/a
Michael,

Both the Process and Console classes have properties and methods to
work with standard input/output/error. You could try some match making
between the two classes. I'm too tired tonight to give it a spin´, but let
us
know how it works out.

HTH,

//Andreas

"Michael A. Covington" <lo**@www.covingtoninnovations.com.for.address> skrev
i meddelandet news:%2****************@TK2MSFTNGP09.phx.gbl...
Ah! Creo que lo que Ud. intenta es que quiere comunicar con otro proceso
por "standard input" y "standard output". No se' como se hace.

Anyone -- How do you get a process to read and write to another process's
stdin and stdout? If you can?
"~toki" <pedorro77.hotmail.com> wrote in message
news:uo**************@TK2MSFTNGP11.phx.gbl...
I have the server source in C# and the client is an .exe (made in C)
I see how talk with a "debug windows" of the client.
The client send two tokens to the server.
And the server response with a token (that exists in the source code) with Console.Write(returnToken);
It works fine.
I can't run the C# server from the MS IDE to stop and debug when the client
send the token.

*The client run the server when it start.

I have tried do it with System.Diagnostic.Process.Start("server.exe")

but it
don't work.
"Michael A. Covington" <lo**@www.covingtoninnovations.com.for.address>
escribió en el mensaje news:ei**************@tk2msftngp13.phx.gbl...

"~toki" <pedorro77.hotmail.com> wrote in message
news:ed**************@TK2MSFTNGP10.phx.gbl...
> I have a full work app (server and client) that talk between two
executables
> trought Console.WriteLine(); & Console.ReadLine();
...
> But never can read anything.
>
> I know good how to make a client server with TCP. But with Console

appears
> to be different.
> When is "established" the connection?

As far as I know, different applications cannot communicate through a
console. Do you have some information indicating that they can?



Nov 16 '05 #5

P: n/a
Pienso que si, consegui el codigo fuente pero no lo puedo compilar.

Here some relevant lines of the client source code. (i don't know C)
/*
* The steps for redirecting child's STDIN:
* 1. Create anonymous pipe to be STDIN for child.
* 2. Create a noninheritable duplicate of write handle,
* and close the inheritable write handle.
*/
/* Create a pipe for the child's STDIN. */
if (! CreatePipe(&hChildStdinRd, &hChildStdinWr, &saAttr, 0)) {
return GetLastError();
}
....
fSuccess = CreateProcess(NULL,
cmdLine, /* command line */
NULL, /* process security attributes */
NULL, /* primary thread security attrs */
TRUE, /* handles are inherited */
DETACHED_PROCESS|CREATE_NEW_PROCESS_GROUP,
NULL, /* use parent's environment */
NULL,
&siStartInfo, /* STARTUPINFO pointer */
&piProcInfo); /* receives PROCESS_INFORMATION */
....

"Michael A. Covington" <lo**@www.covingtoninnovations.com.for.address>
escribió en el mensaje news:%2****************@TK2MSFTNGP09.phx.gbl...
Ah! Creo que lo que Ud. intenta es que quiere comunicar con otro proceso
por "standard input" y "standard output". No se' como se hace.

Anyone -- How do you get a process to read and write to another process's
stdin and stdout? If you can?
"~toki" <pedorro77.hotmail.com> wrote in message
news:uo**************@TK2MSFTNGP11.phx.gbl...
I have the server source in C# and the client is an .exe (made in C)
I see how talk with a "debug windows" of the client.
The client send two tokens to the server.
And the server response with a token (that exists in the source code) with Console.Write(returnToken);
It works fine.
I can't run the C# server from the MS IDE to stop and debug when the client
send the token.

*The client run the server when it start.

I have tried do it with System.Diagnostic.Process.Start("server.exe")

but it
don't work.
"Michael A. Covington" <lo**@www.covingtoninnovations.com.for.address>
escribió en el mensaje news:ei**************@tk2msftngp13.phx.gbl...

"~toki" <pedorro77.hotmail.com> wrote in message
news:ed**************@TK2MSFTNGP10.phx.gbl...
> I have a full work app (server and client) that talk between two
executables
> trought Console.WriteLine(); & Console.ReadLine();
...
> But never can read anything.
>
> I know good how to make a client server with TCP. But with Console

appears
> to be different.
> When is "established" the connection?

As far as I know, different applications cannot communicate through a
console. Do you have some information indicating that they can?



Nov 16 '05 #6

P: n/a
Thanks, it don't work (yet) but i understand where start.

Something like this..

System.Diagnostics.Process p = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo();
info.UseShellExecute = false;
info.CreateNoWindow = false;
info.FileName = app;
info.RedirectStandardOutput = true;
p.StartInfo = info;
p.Start();
p.WaitForExit();
Console.WriteLine( p.StandardOutput.ReadToEnd() );

I will investigate it...

"Michael A. Covington" <lo**@www.covingtoninnovations.com.for.address> escribió en el mensaje news:%2****************@TK2MSFTNGP09.phx.gbl...
Ah! Creo que lo que Ud. intenta es que quiere comunicar con otro proceso
por "standard input" y "standard output". No se' como se hace.

Anyone -- How do you get a process to read and write to another process's
stdin and stdout? If you can?


"~toki" <pedorro77.hotmail.com> wrote in message
news:uo**************@TK2MSFTNGP11.phx.gbl...
I have the server source in C# and the client is an .exe (made in C)
I see how talk with a "debug windows" of the client.
The client send two tokens to the server.
And the server response with a token (that exists in the source code) with
Console.Write(returnToken);
It works fine.
I can't run the C# server from the MS IDE to stop and debug when the

client
send the token.

*The client run the server when it start.

I have tried do it with System.Diagnostic.Process.Start("server.exe") but

it
don't work.
"Michael A. Covington" <lo**@www.covingtoninnovations.com.for.address>
escribió en el mensaje news:ei**************@tk2msftngp13.phx.gbl...

"~toki" <pedorro77.hotmail.com> wrote in message
news:ed**************@TK2MSFTNGP10.phx.gbl...
> I have a full work app (server and client) that talk between two
executables
> trought Console.WriteLine(); & Console.ReadLine();
...
> But never can read anything.
>
> I know good how to make a client server with TCP. But with Console

appears
> to be different.
> When is "established" the connection?

As far as I know, different applications cannot communicate through a
console. Do you have some information indicating that they can?



Nov 16 '05 #7

P: n/a
It works. Here's the code...

System.Diagnostics.Process p = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo();
info.UseShellExecute = false;
info.CreateNoWindow = false;
info.FileName = app; // App filename
info.RedirectStandardOutput = true;
p.StartInfo = info;
p.Start();

p.StandardInput.WriteLine("Hi server. Lets start!!");

while (true)
{
String command = "";
try
{
command = p.StandardOutput.ReadLine();
if (command != null)
if(command.Length > 0)
System.Console.WriteLine(command);
}
catch (IOException ex)
{
// Print an exception to command line and log file
Console.WriteLine(ex.StackTrace);
}
}

"~toki" <pedorro77.hotmail.com> escribió en el mensaje news:Ow**************@TK2MSFTNGP11.phx.gbl...
Thanks, it don't work (yet) but i understand where start.
Something like this..
System.Diagnostics.Process p = new System.Diagnostics.Process();
System.Diagnostics.ProcessStartInfo info = new System.Diagnostics.ProcessStartInfo();
info.UseShellExecute = false;
info.CreateNoWindow = false;
info.FileName = app;
info.RedirectStandardOutput = true;
p.StartInfo = info;
p.Start();
p.WaitForExit();
Console.WriteLine( p.StandardOutput.ReadToEnd() );
I will investigate it...

"Michael A. Covington" <lo**@www.covingtoninnovations.com.for.address> escribió en el mensaje news:%2****************@TK2MSFTNGP09.phx.gbl...
Ah! Creo que lo que Ud. intenta es que quiere comunicar con otro proceso
por "standard input" y "standard output". No se' como se hace.

Anyone -- How do you get a process to read and write to another process's
stdin and stdout? If you can?


"~toki" <pedorro77.hotmail.com> wrote in message
news:uo**************@TK2MSFTNGP11.phx.gbl...
I have the server source in C# and the client is an .exe (made in C)
I see how talk with a "debug windows" of the client.
The client send two tokens to the server.
And the server response with a token (that exists in the source code) with
Console.Write(returnToken);
It works fine.
I can't run the C# server from the MS IDE to stop and debug when the

client
send the token.

*The client run the server when it start.

I have tried do it with System.Diagnostic.Process.Start("server.exe") but

it
don't work.
"Michael A. Covington" <lo**@www.covingtoninnovations.com.for.address>
escribió en el mensaje news:ei**************@tk2msftngp13.phx.gbl...

"~toki" <pedorro77.hotmail.com> wrote in message
news:ed**************@TK2MSFTNGP10.phx.gbl...
> I have a full work app (server and client) that talk between two
executables
> trought Console.WriteLine(); & Console.ReadLine();
...
> But never can read anything.
>
> I know good how to make a client server with TCP. But with Console

appears
> to be different.
> When is "established" the connection?

As far as I know, different applications cannot communicate through a
console. Do you have some information indicating that they can?



Nov 16 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.