我运行exe后如何关闭cmd窗口。文件吗? [英] How to close a cmd window after I ran an exe. file from it?

查看:510
本文介绍了我运行exe后如何关闭cmd窗口。文件吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ac#应用程序(app.exe),我想从命令行窗口运行该应用程序,然后在应用程序启动后关闭命令行窗口。

I have a c# app (app.exe), which I want to run from a command line window and then to CLOSE the command line window after the app started.

我尝试在进程列表中搜索 cmd并关闭它(cmdProcess.CloseMainWindow()),但是在这种情况下,如果我仅通过双击运行app.exe,并且另外一个cmd被单独打开,它将关闭-我不想要那样。
我怎么知道哪个cmd实例运行我的应用程序?

I tried to search for "cmd" in the processes list and to close it (cmdProcess.CloseMainWindow()) but in this case, if I run app.exe by double-click only, and there is another cmd opened separately, it will be closed- and I don't want that. How can I know which cmd instance runs my app?

谢谢

推荐答案

在Windows命令提示符下,它是&将命令附加在一行中。因此它将是:

In Windows Command prompt it's "&" to attach commands in one line. So it'll be:

process.StartInfo.FileName = "cmd.exe";
process.StartInfo.Arguments = "/k " + Command + " & exit";

但是,如果您阅读 cmd /?,则会看到 / k参数是保留窗口。因此,如果不是您想要的,只需使用 / c参数即可。

But if you read the "cmd /?", you'll see that the purpose of "/k" argument is to keep the window. So if it's not what you want, just use the "/c" argument instead.

process.StartInfo.FileName = "cmd.exe";
process.StartInfo.Arguments = "/c " + Command;

这篇关于我运行exe后如何关闭cmd窗口。文件吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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