Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New Coder crank01's Avatar
    Join Date
    Jan 2011
    Posts
    96
    Thanks
    10
    Thanked 2 Times in 2 Posts

    (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

  • #2
    New Coder crank01's Avatar
    Join Date
    Jan 2011
    Posts
    96
    Thanks
    10
    Thanked 2 Times in 2 Posts
    Would I need to disassemble it then compile it in C#? Any one?

  • #3
    New Coder
    Join Date
    Jan 2012
    Location
    RI, USA
    Posts
    24
    Thanks
    1
    Thanked 0 Times in 0 Posts
    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.

  • #4
    New Coder crank01's Avatar
    Join Date
    Jan 2011
    Posts
    96
    Thanks
    10
    Thanked 2 Times in 2 Posts
    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?


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •