如何通过C程序打开Cmd(命令提示符)

发布于 2024-10-15 20:05:35 字数 108 浏览 3 评论 0原文

实际上,我想通过C程序执行DOS命令,并想在我的C输出窗口中显示DOS命令的输出。

示例:

使用“dir C:\”显示 C 程序的输出

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.

example:

use "dir C:\" which displays output to C- program

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

只有一腔孤勇 2024-10-22 20:05:35

要在运行 C 程序的同一 cmd.exe 窗口中执行命令:

#include <stdlib.h>
.
.
.
system("dir C:\\");

要启动单独的窗口,您需要调用 cmd.exe:(

system("cmd.exe /c dir c:\\");

注意:我还没有测试过这个) ;

To execute a command in the same cmd.exe window where your C program is running:

#include <stdlib.h>
.
.
.
system("dir C:\\");

To launch a separate windows, you need to call cmd.exe:

system("cmd.exe /c dir c:\\");

(Note: I have not tested this one);

梦幻之岛 2024-10-22 20:05:35
system("dir");

应该转储到当前的标准输出中

system("dir");

should dump in the current stdout

吾性傲以野 2024-10-22 20:05:35

但 system() 是邪恶的。原因如下: http://www.cplusplus.com/forum/articles/11153/ 确保在使用它之前经过深思熟虑。

But system() is evil. Here's why: http://www.cplusplus.com/forum/articles/11153/ Make sure you give thorough thought before using it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文