简体   繁体   English

如何在不打开新 cmd 窗口的情况下从命令行启动程序?

[英]How do I launch a program from command line without opening a new cmd window?

I'm trying to programmatically execute an external file from cmd using this command:我正在尝试使用以下命令以编程方式从cmd执行外部文件:

START "filepath"

Where "filepath" is the path of my file.其中"filepath"是我文件的路径。 It opens fine but it also open a new command prompt window.它打开得很好,但它也会打开一个新的命令提示符窗口。

So, which is the right command for opening an external program without opening a new window?那么,在不打开新窗口的情况下打开外部程序的正确命令是什么?

In Windows 7+ the first quotations will be the title to the cmd window to open the program:在 Windows 7+ 中,第一个引号将是用于打开程序的cmd窗口的标题:

start "title" "C:\path\program.exe"

Formatting your command like the above will temporarily open a cmd window that goes away as fast as it comes up so you really never see it.像上面那样格式化您的命令将暂时打开一个cmd窗口,该窗口随着出现的速度而消失,因此您真的永远不会看到它。 It also allows you to open more than one program without waiting for the first one to close first.它还允许您打开多个程序而无需等待第一个程序先关闭。

Add /B, as documented in the command-line help for start:添加 /B,如启动的命令行帮助中所述:

C:\>start /?
Starts a separate window to run a specified program or command.

START ["title"] [/D path] [/I] [/MIN] [/MAX] [/SEPARATE | /SHARED]
  [/LOW | /NORMAL | /HIGH | /REALTIME | /ABOVENORMAL | /BELOWNORMAL]
  [/NODE <NUMA node>] [/AFFINITY <hex affinity mask>] [/WAIT] [/B]
  [command/program] [parameters]

"title"     Title to display in window title bar.
path        Starting directory.
B           Start application without creating a new window. The
            application has ^C handling ignored. Unless the application
            enables ^C processing, ^Break is the only way to interrupt
            the application.

Just remove the double quote, this works in Windows 7:只需删除双引号,这适用于 Windows 7:

start C:\ProgramFiles\folderName\app.exe

If you want to maximize the window, try this:如果你想最大化窗口,试试这个:

start /MAX C:\ProgramFiles\folderName\app.exe


Your command START "filepath" will start a command prompt and change the command prompt title to filepath .您的命令START "filepath"将启动命令提示符并将命令提示符标题更改为filepath

Try to run start /?尝试运行start /? in windows command prompt and you will get more info.在 Windows 命令提示符下,您将获得更多信息。

I think if you closed a program我想如果你关闭了一个程序

taskkill /f /im "winamp.exe" 
//....(winamp.exe is example)...

end, so if you want to start a program that you can use结束,所以如果你想启动一个你可以使用的程序

start "" /normal winamp.exe 

(/norma,/max/min are that process value cpu) (/norma,/max/min 是进程值cpu)

ALSO

start "filepath"开始“文件路径” 在此处输入图片说明

if you want command line without openning an new window you write that如果你想要命令行而不打开一个新窗口,你可以这样写

start /b "filepath"开始 /b "文件路径" 在此处输入图片说明

/B is Start application without creating a new window. /B 是启动应用程序而不创建新窗口。 The application has ^C handling ignored.应用程序忽略了 ^C 处理。 Unless the application enables ^C processing, ^Break is the only way to interrupt the application.除非应用程序启用 ^C 处理,否则 ^Break 是中断应用程序的唯一方法。

If you're doing it via CMD as you say, then you can just enter the command like so:如果你像你说的那样通过 CMD 来做,那么你可以像这样输入命令:

path\to\your.exe 

which will open it within the same window.这将在同一窗口中打开它。 For example in C++:例如在 C++ 中:

system("path\\to\\your.exe"); // Double backslash for escaping

will open your.exe in the current CMD window.将在当前 CMD 窗口中打开your.exe Likewise to start with a new window, just go for:同样要从一个新窗口开始,只需:

system("start path\\to\\your.exe");

If you go for the first option, you would have to clear your screen unless you wanted to have the command to open your.exe on the screen still.如果您选择第一个选项,则必须清除屏幕,除非您想让命令仍然在屏幕上打开your.exe

You can use the call command...您可以使用call命令...

Type: call /?类型: call /?

Usage: call [drive:][path]filename [batch-parameters]用法: call [drive:][path]filename [batch-parameters]

For example call "Example File/Input File/My Program.bat" [This is also capable with calling files that have a .exe , .cmd , .txt , etc.例如call "Example File/Input File/My Program.bat" [这也能够调用具有.exe.cmd.txt等的文件。

NOTE: THIS COMMAND DOES NOT ALWAYS WORK!!!注意:这个命令并不总是有效!!!

Not all computers are capable to run this command, but if it does work than it is very useful, and you won't have to open a brand new window...并非所有计算机都能够运行此命令,但是如果它确实有效,那么它非常有用,而且您不必打开一个全新的窗口...

I got it working from qkzhu but instead of using MAX change it to MIN and window will close super fast.我从qkzhu开始工作,但不是使用 MAX 将其更改为 MIN,窗口将关闭得非常快。

@echo off
cd "C:\Program Files (x86)\MySQL\MySQL Server 5.6\bin"
:: Title not needed:
start /MIN  mysqld.exe
exit

20190907 20190907

OS: Win 10操作系统:Win 10

I'm making an exe in c++, for some reason usting START make my program fail.我正在用 C++ 制作一个 exe,出于某种原因使用START使我的程序失败。

So, just use quotes:所以,只需使用引号:

"c:\\folder\\program.exe" “c:\\文件夹\\程序.exe”

1-Open you folder that contains your application in the File Explorer. 1-在文件资源管理器中打开包含您的应用程序的文件夹。 2-Press SHIFT and Right Click in White Space. 2-按 SHIFT 并在空白处右键单击。 3-Click on "Open command window here". 3-单击“在此处打开命令窗口”。 4-Run your application. 4-运行您的应用程序。 (you can type some of the first characters of application name and press Up Arrow Key OR Down Arrow Key) (您可以输入应用程序名称的前几个字符,然后按向上箭头键或向下箭头键)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我如何在Windows中启动新的PHP实例而不打开新的CMD窗口? - How do I start a new instance of PHP in Windows without it opening a new CMD window? 如何在不打开VB6中的CMD窗口的情况下运行Shell命令 - How to run a shell command without opening a CMD window in VB6 如何从命令行启动该程序? - How to launch this program from the command line? 如何使用Cygwin的正确路径启动新的cmd窗口? - How to launch a new cmd window with the correct path from Cygwin? 在不打开新窗口的情况下从 cmd 脚本打开另一个 cmd 脚本 - Open another cmd script from a cmd script without opening a new window 如何在 Inno Setup 中不打开新窗口的情况下运行 CMD 命令 - How to run a CMD command without openning a new window in Inno Setup 我可以在没有换行的情况下运行CMD命令吗? - Can I run a CMD command without a new line? 无需打开命令行窗口,直接启动 .csx (scriptcs) C# 脚本 - Launch a .csx (scriptcs) C# script directly without opening a command line window 如何从sh脚本打开新的命令行窗口,然后传入多个命令 - How do I open a new command line window from an sh script and then pass in multiple commands 如何在不打开窗口的情况下调用CMD - How to call CMD without opening a window
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM