You can capture the standard output of a program by redirecting it to your own handle.
C++ and C libraries do not, as far as I'm aware, expose this capability. You would need to directly access the Windows API functions. In this case, the applicable function is CreateProcess(). You pass in a PROCESS_START_INFO structure, and that structure can include setting a handle on the standard output.
The usual approach is to create a new stream and redirect the standard output of the child process to that stream. Then the parent can read from that stream until the EOF and it will have the standard output of the program. If the program requires standard input (eg text-based prompts or something) those can be written to a redirected standard input.
I don't have an example in C/C++ and personally think it would take far too long for me to come up with one that actually works to make it worth it. Here is a C# example though:
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Security.Principal;
using System.Text;
using System.Windows.Forms;
namespace testredirection
{
class Program
{
[STAThread]
static void Main(string[] args)
{
String strFile = "getmac.exe";
String strarguments = "/v";
ProcessStartInfo psi = new ProcessStartInfo()
{
FileName = strFile,
Arguments = strarguments,
RedirectStandardOutput = true,
WindowStyle=ProcessWindowStyle.Hidden
};
psi.UseShellExecute = false;
Process p = Process.Start(psi);
String stdouttext = p.StandardOutput.ReadToEnd();
Console.WriteLine("Standard output retrieved:\n" + stdouttext);
Clipboard.SetText(stdouttext);
}
}
}
After I run the above C# code I end up with getmac /v output on my clipboard. Obviously a program that does additional parsing can easily parse that string and only set the appropriate text, as per the instructions you gave.
If it needs to be or would be preferred to be in C++/C, you would need to include Windows.h and you would use the PROCESS_START_INFO structure in combination with CreateProcess. You would then create a pipe (using CreatePipe) and set the hStdOutput member of PROCESS_START_INFO to point at the pipe you created, the nread from the Pipe until EOF and use that as the process output. Once you have the output you would then open the clipboard and set the text to it. as we can
see here doing the same thing in C or C++ is a bit more complex, but perhaps you can use that as a starting point.