سؤال

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

هل كانت مفيدة؟

المحلول

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'm not sure I understand the question correctly. But if I do, you're looking for the system() function.

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
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top