0

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.

Raheel Khan
  • 14,205
  • 13
  • 80
  • 168

1 Answers1

0

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.

Community
  • 1
  • 1
Dustin Kingen
  • 20,677
  • 7
  • 52
  • 92