Pregunta

I need to write some commands in command window using C++ code. How to implement it. I have tried with CreateProcess function but it seems some wrong in it. Please refer my code below:

 STARTUPINFO sInfo = {0};
sInfo.cb = sizeof(sInfo);
PROCESS_INFORMATION pInfo = {0};

CreateProcess("C:\\WINDOWS\\System32\\cmd.exe",""0,0,TRUE,
    NORMAL_PRIORITY_CLASS,0,0,&sInfo,&pInfo);

It opens the command window successfully. My doubt is how to write command through code in it.

¿Fue útil?

Solución

First thing, you need not to create a separate process just to write text output to a console window.

It depends what and how you want to write. You may create a console application itself, or create a console itself, and attach to the current process. You need to use pipes for the same and redirect the output to given pipe (i.e. send data to pipe). At the other end of pipe, you will read the text/buffer and render the output wherever you would like to.

These articles may help:

Since your question is not very clear, this is just assumption. Or, are you playing with the console itself - like changing colors, dimension etc?

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top