简体   繁体   中英

How can I pass inputs from my C program to another program running in the command line? [on hold]

I want to provide inputs to a program (not written by me) running in command line through a c or c++ program (which I did write).

I tried googling but didn't get a proper answer. Please check the image for more information

https://i.stack.imgur.com/oA5BM.png

if you're using C : Use : scanf(); and if you're using C++ : use : std::cin >> ();

Try the code from this article:

https://support.microsoft.com/en-us/help/190351/how-to-spawn-console-processes-with-redirected-standard-handles

Basically, you already have child (y-cruncher exe file) and you need to copy the code of redirector (your c file). Don't forget to change you exe name:

CreateProcess(NULL,"D:\\nerd_stuff\\project\\y-cruncher_v0.7.7.9501\\y-cruncher.exe",NULL,NULL,TRUE,CREATE_NEW_CONSOLE,NULL,NULL,&si,&pi)

And set proper buffer size here:

if(!ReadConsole(hStdIn,read_buff,1,&nBytesRead,NULL))
            DisplayError("ReadConsole");

Should be:

if(!ReadConsole(hStdIn,read_buff,sizeof(read_buff),&nBytesRead,NULL))
            DisplayError("ReadConsole");

All these means, that you will be able to work as though you are "directly" working with y-cruncher. You will be able to process its output (whatever logic you wish to insert) and generate appropriate input in your code.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM