[英]How to Open Cmd(Command Prompt) through C program
Actually, I want to execute DOS command by a C program and want to display the output of DOS command in my C Output Window. 实际上,我想通过C程序执行DOS命令,并希望在我的C输出窗口中显示DOS命令的输出。
example: 例:
use "dir C:\\" which displays output to C- program 使用“dir C:\\”将输出显示给C程序
To execute a command in the same cmd.exe
window where your C program is running: 要在运行C程序的同一cmd.exe
窗口中执行命令:
#include <stdlib.h>
.
.
.
system("dir C:\\");
To launch a separate windows, you need to call cmd.exe
: 要启动单独的窗口,您需要调用cmd.exe
:
system("cmd.exe /c dir c:\\");
(Note: I have not tested this one); (注意:我没有测试过这个);
But system() is evil. 但是system()是邪恶的。 Here's why: http://www.cplusplus.com/forum/articles/11153/ Make sure you give thorough thought before using it. 原因如下: http: //www.cplusplus.com/forum/articles/11153/确保在使用前仔细考虑。
system("dir");
应该在当前的标准输出中转储
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.