I've searched around and didn't find anything useful! :(

What i want is to have my C# app doing a command to a running process. This running process is a console application and i just need to enter the command "restart".. my try was:

Process[]  processes=  Process.GetProcessesByName("OpenSim.32BitLaunch");

        foreach  (Process  p in  processes)
        {
             p.StandardInput.WriteLine("restart");
                 p.StartInfo.RedirectStandardInput = true;
               p.StartInfo.UseShellExecute = false;

                p.Start();

               StreamWriter myStreamWriter = p.StandardInput;
               myStreamWriter.WriteLine("tdfsffds");
               p.StandardInput.WriteLine("restart");
               p.StandardInput.Write("restart");
}

And i get and exectipon: StandardIn not redirected.I've tried also to set RedirectStandardInput but nothing ..
I've also tried with no success to do:

Process[]  processes=  Process.GetProcessesByName("OpenSim.32BitLaunch");

        foreach  (Process  pin  processes)
        {
                       p.StartInfo.RedirectStandardInput = true;
               p.StartInfo.UseShellExecute = false;

                p.Start();

               StreamWriter myStreamWriter = p.StandardInput;
               myStreamWriter.WriteLine("tdfsffds");
               p.StandardInput.WriteLine("restart");
               p.StandardInput.Write("restart");
    }

And i get and exectipon: StandardIn not redirected.I've tried also to set RedirectStandardInput but nothing .. :(

Can anyone help me ?

Regards!

You can't take over the standard input of an already running process. You can send keystrokes to a window using something like the method here

commented: Solved with the keystrokes :) +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.