7 Replies - 2099 Views - Last Post: 29 January 2012 - 09:07 AM Rate Topic: -----

#1 aquahoya  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 59
  • Joined: 08-January 12

Using external console application alongside C# windows app

Posted 28 January 2012 - 10:59 AM

Greetings,
I am trying to use a console application(.exe) inside my .Net C# windows application, however I have a feeling this may not be possible. I did not write the console application and do not have the source code, but I would love to use it in my windows application(I wont be infringing on copyrights in case anyones wondering).

Now to get to the menu within the console app, you need to press 'Enter' and then from there I would like a user to input digits inside my Windows Application Textbox, and those digits will carry to the Console Application, then press Enter to submit.

I am not looking for code, just if you may find me a tutorial on how I could possibly do this, and what I would need. I hope it won't come down to the point where I would need to disassemble the console application then rewrite it in C# :dontgetit:

Thanks :sweatdrop:

Is This A Good Question/Topic? 0
  • +

Replies To: Using external console application alongside C# windows app

#2 RexGrammer  Icon User is offline

  • Coding Dynamo
  • member icon

Reputation: 181
  • View blog
  • Posts: 777
  • Joined: 27-October 11

Re: Using external console application alongside C# windows app

Posted 28 January 2012 - 11:19 AM

You would have to use IPC (Inter Process Comunication):

Some links on it:
Interprocess Communication using Named Pipes in C#
Inter-Process Communication with C#
Inter-Process Communication in .NET Using Named Pipes

There's also been a similar discussion on StackOverflow:
link


Here's an example on how to read output from a console application and to send input to it:

InterProc.StartInfo.UseShellExecute = false;
InterProc.StartInfo.FileName = "app.exe";
InterProc.StartInfo.RedirectStandardInput = true;
InterProc.StartInfo.RedirectStandardOutput = true;
InterProc.StartInfo.RedirectStandardError = true;
InterProc.StartInfo.CreateNoWindow = true;
InterProc.OutputDataReceived += new DataReceivedEventHandler(InterProcOutputHandler);

private static void InterProcOutputHandler(object sendingProcess, DataReceivedEventArgs outLine)
    {
        if (!String.IsNullOrEmpty(outLine.Data))
        {
           OutputTextBox.Append(Environment.NewLine + outLine.Data);
        }
    }

private void PassInput(string inputToPass)
    {
        InterProc.StandardInput.Write(inputToPass);
        InterProc.BeginOutputReadLine();
    }


Was This Post Helpful? 0
  • +
  • -

#3 aquahoya  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 59
  • Joined: 08-January 12

Re: Using external console application alongside C# windows app

Posted 28 January 2012 - 11:38 AM

thanks so much again Rex :donatello:

are you really that young, cuz I'm impressed by everything you know :bigsmile:
Was This Post Helpful? 0
  • +
  • -

#4 RexGrammer  Icon User is offline

  • Coding Dynamo
  • member icon

Reputation: 181
  • View blog
  • Posts: 777
  • Joined: 27-October 11

Re: Using external console application alongside C# windows app

Posted 28 January 2012 - 02:28 PM

Yup I'm that young. But mostly it isn't my previous knowledge that gets the answer it's my ability to search the web and to quickly learn what I need.
Was This Post Helpful? 0
  • +
  • -

#5 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1524
  • View blog
  • Posts: 5,957
  • Joined: 21-March 08

Re: Using external console application alongside C# windows app

Posted 28 January 2012 - 05:35 PM

RexGrammer, the code you posted is not inter-process communication, in the sense of the links you posted.

Inter-process communication will not work in this instance(even though you state it will). The console app is not his. Inter-process communication works when both apps are yours. One has to be accepting data through inter-process communication for it to work. You can't just send data through inter-process communication to any app that is running. It won't work.
Was This Post Helpful? 0
  • +
  • -

#6 aquahoya  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 59
  • Joined: 08-January 12

Re: Using external console application alongside C# windows app

Posted 28 January 2012 - 08:33 PM

hello eclipsed, so is what I'm trying to do impossible? Is there any possible way to do what I described?
Was This Post Helpful? 0
  • +
  • -

#7 RexGrammer  Icon User is offline

  • Coding Dynamo
  • member icon

Reputation: 181
  • View blog
  • Posts: 777
  • Joined: 27-October 11

Re: Using external console application alongside C# windows app

Posted 29 January 2012 - 04:11 AM

Yeah, the other application has to handle the input sent from the first one in some way (and that must be done by managed code). But you can inject code into that application. Of course you should first ask for a modification permit by the original owner.

And the example is just some code extracted from here:
Sending input/getting output from a console application (C#/WinForms)

(I linked that topic in my previous post)
Was This Post Helpful? 0
  • +
  • -

#8 aquahoya  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 59
  • Joined: 08-January 12

Re: Using external console application alongside C# windows app

Posted 29 January 2012 - 09:07 AM

:sweatdrop: I'm glad that it is possible for me to accomplish this. As far as I know the author is unknown, according to google. I won't be modifying the source code and will only be using the console application alongside my own windows application right? I'll state that the console app isn't mine regardless though :turned:

Thanks for your help again, if I have any problems while trying to get this to work I'll create another thread.
:batman:
thx
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1