1

How can I call a DOS command and retrieve its output from a windows program that I will program in C/C++?

My prog would be like a "front-end" for the DOS command.

nvoigt
  • 75,013
  • 26
  • 93
  • 142
  • @Ron there are [several](https://stackoverflow.com/questions/478898), [equivalent](https://stackoverflow.com/questions/5919622) questions for Unix. Is Windows dramatically more broad? – Drew Dormann Apr 23 '18 at 15:51
  • 2
    @DrewDormann I see. You are probably right. I will retract the close vote. WinAPI really is too broad. – Ron Apr 23 '18 at 15:53

1 Answers1

0

The easiest way (IMHO) is to spawn the DOS application as a new process and connect your standard output to its standard input and its standard output and standard error to your standard input, using pipes. Then you can communicate with the child process by simply writing to standard out and get output from the child by reading from standard in.

Jesper Juhl
  • 30,449
  • 3
  • 47
  • 70
  • 1
    https://msdn.microsoft.com/en-us/library/windows/desktop/ms682499%28v=vs.85%29.aspx complete example from microsoft page – Rubén Pozo Apr 23 '18 at 16:04
  • @Alain Paré Rather than posting a "thank you" comment you should accept the answer if it answered your question (of course only if it did indeed solve your problem). Thank you appreciated in any case :) – Jesper Juhl Apr 30 '18 at 18:11