3

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"); } 
1
  • Just because you're looping through processes, that doesn't mean any statements inside the loop are doing anything to the processes. Console.WriteLine writes text to standard output, and has nothing to do with p. Commented Sep 12, 2011 at 21:50

3 Answers 3

4

You should write to p.StandardInput.

Sign up to request clarification or add additional context in comments.

3 Comments

says that non-invocabble membet cant be used like a method :( tried StandardInput.Writeline("restart"); but got an execption :(
Ty by your help... i got InvalidOperationException was unhandled .. StandardIn not redirected
hmmm so you are saying that i cant do what i want?
1

Instead of

Console.WriteLine("restart"); 

Use

p.StandardInput.WriteLine("restart"); 

1 Comment

tried StandardInput.Writeline("restart"); but got an execption.. StandardIn not redirected :(
1

Thanks by your help guys :) I've managed to solve using SetForegroundWindow and SendKeys. It was something just like this (remember to import the respective dll's first):

System.Diagnostics.Process process = Process.GetProcessesByName("OpenSim.32BitLaunch")[0]; Process[] processes = Process.GetProcessesByName("OpenSim.32BitLaunch"); foreach (Process p in processes) { SetForegroundWindow(p.MainWindowHandle); Thread.Sleep(1000); SendKeys.SendWait("quit"); Thread.Sleep(1000); SendKeys.SendWait("{ENTER}"); } 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.