Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I have a training and testing application that tells gives users certain tasks and then programmatically determines whether they have been performed. One of the tasks is typing something in the command line prompt "dir /s" for example.

I know I can redirect the input/output of an instance of "cmd.exe" that my own application creates but how can I do the same for an instance that the user has launched?

Also, I want the user to be able to see results of their actions in the command-prompt rather than my app silently swallowing them.

share|improve this question
 
Console.ReadLine, Console.ReadKey and the like. –  Corak Jun 13 '13 at 14:52
add comment

1 Answer

You can use the Process class to find the process.

Process.GetProcessesByName("cmd")

Which will return an array of cmd processes.

See: Process.GetProcessesByName

See Determine if current application is activated (has focus) to determine which process has focus.

After that you can redirect the output of the process to your application.

share|improve this answer
 
Thanks. When I redirect the output to my application, will I also be able to display the results back to the window as if no monitor was attached to it? –  Raheel Khan Jun 13 '13 at 16:25
 
I don't know. You will need to try it and find out. –  Romoku Jun 13 '13 at 16:32
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.