-3

How do I look for a file or program on a system and open it?

Let me explain; My project is something I've made in vb called Program OS and I want to make Program OS Modern using c#. So because people will install it on there system I don't want to compile the code and find that no one can open the other program.

So I want my program to look for the other program. (which will be a console application)

{I'm currently using the c# windows forms.}

So if anyone knows how I could maybe open another c# console application with in the windows forms applications that I am using.

Thanks in advance

Dan

Ňɏssa Pøngjǣrdenlarp
  • 38,411
  • 12
  • 59
  • 178
Daniel Morris
  • 51
  • 1
  • 2
  • 11
  • You cannot open a console application 'in' a winforms app. You could open it by your winforms app though. Look for process.Start(). – Tobias Knauss Aug 23 '15 at 16:33
  • possible duplicate of [Launching a Application (.EXE) from C#?](http://stackoverflow.com/questions/240171/launching-a-application-exe-from-c) – Jens Aug 23 '15 at 17:02

1 Answers1

0

You can start it with Process.Start(@"c:\path\to\my\app.exe");

If you want to see what it prints out and to write something on its console, you want to redirect its standard input and output. Then you want to use the ProcessStartInfo class, in which you can do these.

        ProcessStartInfo psi = new ProcessStartInfo() {
            FileName = @"C:\path\to\your\app.exe",
            CreateNoWindow = true, // To hide the console window
            RedirectStandardInput = true,
            RedirectStandardOutput = true
        };

        Process p = Process.Start(psi);

The Process object 'p' has a StandardInput and a StandardOutput Stream. You can write this the same way you would write and read from a file.

tvili999
  • 101
  • 4