Go Back   CodingForums.com > :: Computing & Sciences > Computer Programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-28-2012, 05:03 AM   PM User | #1
crank01
New Coder

 
crank01's Avatar
 
Join Date: Jan 2011
Posts: 96
Thanks: 10
Thanked 2 Times in 2 Posts
crank01 is an unknown quantity at this point
(C#)Is this even remotely possible?

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
crank01 is offline   Reply With Quote
Old 01-28-2012, 04:44 PM   PM User | #2
crank01
New Coder

 
crank01's Avatar
 
Join Date: Jan 2011
Posts: 96
Thanks: 10
Thanked 2 Times in 2 Posts
crank01 is an unknown quantity at this point
Would I need to disassemble it then compile it in C#? Any one?
crank01 is offline   Reply With Quote
Old 01-28-2012, 06:07 PM   PM User | #3
Alternative
New Coder

 
Join Date: Jan 2012
Location: RI, USA
Posts: 24
Thanks: 1
Thanked 0 Times in 0 Posts
Alternative is an unknown quantity at this point
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:

Code:
                    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.
Alternative is offline   Reply With Quote
Old 01-28-2012, 06:33 PM   PM User | #4
crank01
New Coder

 
crank01's Avatar
 
Join Date: Jan 2011
Posts: 96
Thanks: 10
Thanked 2 Times in 2 Posts
crank01 is an unknown quantity at this point
Quote:
Originally Posted by Alternative View Post
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:

Code:
                    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?
crank01 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:52 AM.


Advertisement
Log in to turn off these ads.