...

View Full Version : (C#)Is this even remotely possible?



crank01
01-28-2012, 06:03 AM
Hello :)

I have been creating a windows application and I would love to use an existing console application(i didn't make it) inside the windows application I have made.

Now is this possible CF: to get to the menu screen of the console application it requires me to type 'Enter' within the console app. From my Windows application, I'm going to create a text box where the user can input numbers, and I was HOPING that its possible to carry those numbers from the windows app, into the console application awaiting for me to input numbers. And then obviously press 'Enter'; hopefully hidden.

I know this may seem crazy, but I require this to somehow work inside my windows application. I know it would require alot of time I'm sure, I just would really like to know How I could possibly do this :thumbsup:

crank01
01-28-2012, 05:44 PM
Would I need to disassemble it then compile it in C#? Any one?

Alternative
01-28-2012, 07:07 PM
If I understand you right, this is quite possible, and I myself have been trying to do it. You want to basically pass a variable from C# into a console app, and automatically run it, then return the value into C#?

First import System.Diagnostics and System.IO into C#, then:



string call = @"""(the path to your console app)""";
string param1 = @"""(console param1)""";

string param2 = "(console param2)";

Process theProcess = new Process();

string args = string.Format("{0} {1}", param1, param2);
ProcessStartInfo theProcessStartInfo = new ProcessStartInfo(call, "spawn");
theProcessStartInfo.UseShellExecute = false;
theProcessStartInfo.RedirectStandardOutput = true;

theProcessStartInfo.Arguments = args;
theProcess.StartInfo = theProcessStartInfo;

theProcess.Start();
StreamReader theStreamReader = theProcess.StandardOutput;

while (theStreamReader.ReadLine() != null) {
string name = theStreamReader.ReadLine();
MessageBox.Show(name);
}


This will call the console app and automatically run it with param1 and param2. In other words, it would be the same as doing this in the command prompt:

"(the path to your console app)" "(console param1)" (console param2)

and pressing enter. If you need quotes inside the actual command, in C# you need to use @"""(param)""" so that the double quotes will make it to the console.

Is this what you are looking for? I am still having some trouble getting this to completely work...let me know if this is what you're trying to do, as well.

crank01
01-28-2012, 07:33 PM
If I understand you right, this is quite possible, and I myself have been trying to do it. You want to basically pass a variable from C# into a console app, and automatically run it, then return the value into C#?

First import System.Diagnostics and System.IO into C#, then:



string call = @"""(the path to your console app)""";
string param1 = @"""(console param1)""";

string param2 = "(console param2)";

Process theProcess = new Process();

string args = string.Format("{0} {1}", param1, param2);
ProcessStartInfo theProcessStartInfo = new ProcessStartInfo(call, "spawn");
theProcessStartInfo.UseShellExecute = false;
theProcessStartInfo.RedirectStandardOutput = true;

theProcessStartInfo.Arguments = args;
theProcess.StartInfo = theProcessStartInfo;

theProcess.Start();
StreamReader theStreamReader = theProcess.StandardOutput;

while (theStreamReader.ReadLine() != null) {
string name = theStreamReader.ReadLine();
MessageBox.Show(name);
}


This will call the console app and automatically run it with param1 and param2. In other words, it would be the same as doing this in the command prompt:

"(the path to your console app)" "(console param1)" (console param2)

and pressing enter. If you need quotes inside the actual command, in C# you need to use @"""(param)""" so that the double quotes will make it to the console.

Is this what you are looking for? I am still having some trouble getting this to completely work...let me know if this is what you're trying to do, as well.
Yes! this is exactly what I'm trying to do =) See the console application output a picture, based on what numbers I put into it. I dont want the user of my C# Windows Application to use another application just to get that picture! lol I'll probably be having difficulty on it still but I'm glad its possible :)

Now in what ways are you having difficulty in making it Completely work?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum