windows 如何在不打开新的 cmd 窗口的情况下从命令行启动程序?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12010103/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How do I launch a program from command line without opening a new cmd window?
提问by Andrei20193
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. It opens fine but it also open a new command prompt window.
"filepath"
我的文件路径在哪里。它打开得很好,但它也会打开一个新的命令提示符窗口。
So, which is the right command for opening an external program without opening a new window?
那么,在不打开新窗口的情况下打开外部程序的正确命令是什么?
回答by Matt - MCTS
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. It also allows you to open more than one program without waiting for the first one to close first.
像上面那样格式化您的命令将暂时打开一个cmd
窗口,该窗口随着出现的速度而消失,因此您真的永远不会看到它。它还允许您打开多个程序而无需等待第一个程序先关闭。
回答by John Watts
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.
回答by Frank
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 /?
in windows command prompt and you will get more info.
尝试start /?
在 Windows 命令提示符下运行,您将获得更多信息。
回答by lscodex
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
还
if you want command line without openning an new window you write that
如果你想要命令行而不打开一个新窗口,你就写
/B is 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.
/B 是启动应用程序而不创建新窗口。应用程序忽略了 ^C 处理。除非应用程序启用 ^C 处理,否则 ^Break 是中断应用程序的唯一方法。
回答by Shersha Fn
回答by jaimeandrescatano
20190907
20190907
OS: Win 10
操作系统:Win 10
I'm making an exe in c++, for some reason usting STARTmake my program fail.
我正在用 C++ 制作一个 exe,出于某种原因使用START使我的程序失败。
So, just use quotes:
所以,只需使用引号:
"c:\folder\program.exe"
“c:\文件夹\程序.exe”
回答by Fait Wise
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...
并非所有计算机都能够运行此命令,但是如果它确实有效,那么它非常有用,而且您不必打开一个全新的窗口...
回答by whitfin
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. Likewise to start with a new window, just go for:
将your.exe
在当前 CMD 窗口中打开。同样要从一个新窗口开始,只需:
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
仍然在屏幕上打开。
回答by Ghorban ali arabi
1-Open you folder that contains your application in the File Explorer. 2-Press SHIFT and Right Click in White Space. 3-Click on "Open command window here". 4-Run your application. (you can type some of the first characters of application name and press Up Arrow Key OR Down Arrow Key)
1-在文件资源管理器中打开包含您的应用程序的文件夹。2-按 SHIFT 并在空白处右键单击。3-单击“在此处打开命令窗口”。4-运行您的应用程序。(您可以输入应用程序名称的前几个字符,然后按向上箭头键或向下箭头键)