简体   繁体   中英

Executing command through a c program on Windows

I want to know how to execute a command from ac program,on windows os. To be more specific how to write ac program whose output will not be printed but directly goes to command prompt and get executed there? please help me

I'm not sure I understand the question correctly. But if I do, you're looking for the system() function.

I think you need to use system() command in your C code. For example:

system("pause");

where "pause" is the command to be executed in cmd.

reference: http://www.cplusplus.com/reference/cstdlib/system/

I hope i got your question right.

I suspect what you are describing is the the back-ticks in shells in Linux/Unix.

However, I don't know how to do that in Windows.

Unix way

myprompt>  `./a.out`

If the C program was basically: printf("ls -l .\\n"); , then this should list the files.
Is that what you wanted?

Like I said, I don't know how to do that in the Win Cmd Prompt, but maybe this clarifies your question.


Looks like you could try:

C:\MyDir> MyProgram.exe | cmd.exe /C

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