如何在我的Windows窗体应用程序中保持打开命令提示符在c + +? [英] How can I keep open the command prompt in my windows form application in c++?

查看:207
本文介绍了如何在我的Windows窗体应用程序中保持打开命令提示符在c + +?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Visual Studio 2010中用C ++在Windows窗体应用程序中编写了一个项目。我需要打开cmd,然后输入特殊命令并运行其他程序。

I wrote a project in windows form application in C++ by Visual Studio 2010. I need to open the cmd and then type special command and run other program.

我使用这个函数:

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

但是通过这个函数我刚刚看到cmd一秒钟,然后它消失了。
然后我添加这行:

but by this function I just saw cmd for a second and then it was disappeared. then I add this line :

cin.get();

但不起作用。

我也使用这个函数:

char program[] = "C:\Windows\System32\cmd.exe";
WinExec((LPCSTR)program, SW_SHOWMINIMIZED);

但它没有工作!

推荐答案

您尝试过以下吗?

system(cmd / k dir c:\\);

/ k 在执行过程终止后保持cmd提示符窗口打开。

/k keeps the cmd prompt window open after the executing process has terminated.

但是,老实说,使用Windows Terminal Services API进行更精细的控制,如果你愿意的话。

But, to be honest, it may be better to use the Windows Terminal Services API for finer control, if you so desire. But, depending on what you want to do - that might be overkill.

然而,关于你的第二个问题:不要忘记在你的反斜杠中转义:

And, regarding your second question: don't forget to escape your backslashes in:

const char program[] = "C:\\Windows\\System32\\cmd.exe";
WinExec((LPCSTR)program, SW_SHOWMINIMIZED);

参考文献:
http://superuser.com/questions/306167/how-to-prevent-the-command-prompt-from-closing - 执行后

这篇关于如何在我的Windows窗体应用程序中保持打开命令提示符在c + +?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆