windows 使用带有传递给启动程序的参数的“start”命令

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/154075/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 05:26:43  来源:igfitidea点击:

Using the "start" command with parameters passed to the started program

windowscommand-prompt

提问by JosephStyons

I have a Virtual Machine in Virtual PC 2007.

我在 Virtual PC 2007 中有一个虚拟机。

To start it from the desktop, I have the following command in a batch file:

要从桌面启动它,我在批处理文件中有以下命令:

"c:\program files\Microsoft Virtual PC\Virtual PC.exe" -pc "MY-PC" -launch

But that leaves a dos prompt on the host machine until the virtual machine shuts down, and I exit out of the Virtual PC console. That's annoying.

但这会在主机上留下一个 dos 提示,直到虚拟机关闭,然后我退出 Virtual PC 控制台。这很烦人。

So I changed my command to use the START command, instead:

所以我改变了我的命令以使用 START 命令,而不是:

start "c:\program files\Microsoft Virtual PC\Virtual PC.exe" -pc MY-PC -launch

But it chokes on the parameters passed into Virtual PC.

但它会因传递给 Virtual PC 的参数而窒息。

START /?indicates that parameters do indeed go in that location. Has anyone used START to launch a program with multiple command-line arguments?

START /?表示参数确实在那个位置。有没有人使用 START 启动带有多个命令行参数的程序?

回答by Tim Farley

START has a peculiarity involving double quotes around the first parameter. If the first parameter has double quotes it uses that as the optional TITLE for the new window.

START 有一个特殊性,涉及第一个参数周围的双引号。如果第一个参数有双引号,它将用作新窗口的可选 TITLE。

I believe what you want is:

我相信你想要的是:

start "" "c:\program files\Microsoft Virtual PC\Virtual PC.exe" -pc MY-PC -launch

In other words, give it an empty title before the name of the program to fake it out.

换句话说,在程序名称之前给它一个空标题来伪造它。

回答by Ferruccio

Instead of a batch file, you can create a shortcut on the desktop.

您可以在桌面上创建快捷方式而不是批处理文件。

Set the target to:

将目标设置为:

"c:\program files\Microsoft Virtual PC\Virtual PC.exe" -pc "MY-PC" -launch

and you're all set. Since you're not starting up a command prompt to launch it, there will be no DOS Box.

你已经准备好了。由于您没有启动命令提示符来启动它,因此不会有 DOS 框。

回答by ghostdog21

The spaces are DOSs/CMDs Problems so you should go to the Path via:

空格是 DOSs/CMDs 问题,所以你应该通过以下方式进入路径:

cd "c:\program files\Microsoft Virtual PC"

and then simply start VPC via:

然后只需通过以下方式启动 VPC:

start Virtual~1.exe -pc MY-PC -launch

~1means the first exewith "Virtual"at the beginning. So if there is a "Virtual PC.exe"and a "Virtual PC1.exe"the first would be the Virtual~1.exeand the second Virtual~2.exeand so on.

~1表示第一个exe"Virtual"开头。因此,如果有 a"Virtual PC.exe"和 a "Virtual PC1.exe",第一个将是Virtual~1.exe第二个Virtual~2.exe,依此类推。

Or use a VNC-Client like VirtualBox.

或者使用像 VirtualBox 这样的 VNC 客户端。

回答by JustAnotherMikhail

None of these answers worked for me.

这些答案都不适合我。

Instead, I had to use the Call command:

相反,我不得不使用 Call 命令:

Call "\Path To Program\Program.exe" <parameters>

I'm not sure this actually waits for completion... the C++ Redistributable I was installing went fast enough that it didn't matter

我不确定这是否真的在等待完成......我正在安装的 C++ Redistributable 运行得足够快,这无关紧要

回答by Mustafa Kemal

If you must use double quotation mark at any parameter, you can get error "'c:\somepath' is not recognized a an internal or external command, operable program or batch file". I suggest below solution when using double qoutation mark: https://stackoverflow.com/a/43467194/3835640

如果必须在任何参数上使用双引号,则会出现错误“'c:\somepath' 不是内部或外部命令、可运行的程序或批处理文件”。使用双引号时,我建议以下解决方案:https://stackoverflow.com/a/43467194/3835640

回答by Mrbios

You can use quotes by using the [/D"Path"] use /Donlyfor specifying the path and not the path+program. It appears that all code on the same line that follows goes back to normal meaning you don't need to separate path and file.

您可以通过使用 [ /D"Path"]来使用引号,/D用于指定路径而不是路径+程序。似乎后面同一行上的所有代码都恢复正常,这意味着您不需要将路径和文件分开。

    start  /D "C:\Program Files\Internet Explorer\" IEXPLORE.EXE

or:

或者:

    start  /D "TITLE" "C:\Program Files\Internet Explorer\" IEXPLORE.EXE

will start IE with default web page.

将使用默认网页启动 IE。

    start  /D "TITLE" "C:\Program Files\Internet Explorer\" IEXPLORE.EXE www.bing.com

starts with Bing, but does not reset your home page.

以 Bing 开头,但不会重置您的主页。

/Dstands for "directory" and using quotes is OK!

/D代表“目录”,使用引号是可以的!

WRONG EXAMPLE:

错误的例子:

    start  /D "TITLE" "C:\Program Files\Internet Explorer\IEXPLORE.EXE"

gives:

给出:

ERROR "The current directory is invalid."

错误“当前目录无效。

/Dmust only be followed by a directory path. Then space and the batchfile or program you wish to start/run

/D后面只能跟一个目录路径。然后空格和您希望启动/运行的批处理文件或程序

Tested and works under XP but windows Vista/7/8 may need some adjustments to UAC.

在 XP 下测试和工作,但 windows Vista/7/8 可能需要对 UAC 进行一些调整。

-Mrbios

-Mbios

回答by BitDreamer

The answer in "peculiarity" is correct and directly answers the question. As TimF answered, since the first parameter is in quotes, it is treated as a window title.

“特殊性”中的答案是正确的,直接回答了问题。正如 TimF 回答的那样,由于第一个参数在引号中,因此它被视为窗口标题。

Also note that the Virtual PC options are being treated as options to the 'start' command itself, and are not valid for 'start'. This is true for all versions of Windows that have the 'start' command.

另请注意,Virtual PC 选项被视为“start”命令本身的选项,对“start”无效。这适用于所有具有“开始”命令的 Windows 版本。

This problem with 'start' treating the quoted parameter as a title is even more annoying that just the posted problem. If you run this:

'start' 将引用的参数视为标题的这个问题比仅发布的问题更烦人。如果你运行这个:

start "some valid command with spaces"

You get a new command prompt window, with the obvious result for a window title. Even more annoying, this new window doesn't inherit customized font, colors or window size, it's just the default for cmd.exe.

你会得到一个新的命令提示符窗口,窗口标题的结果很明显。更烦人的是,这个新窗口并没有继承自定义的字体、颜色或窗口大小,它只是 cmd.exe 的默认设置。

回答by Mack

If you want passing parameter and your .exe file in test folder of c: drive

如果您想在 c: 驱动器的测试文件夹中传递参数和您的 .exe 文件

start "parameter" "C:\test\test1.exe" -pc My Name-PC -launch

start "parameter" "C:\test\test1.exe" -pc My Name-PC -launch

If you won't want passing parameter and your .exe file in test folder of c: drive

如果您不想在 c: 驱动器的测试文件夹中传递参数和 .exe 文件

start "" "C:\test\test1.exe" -pc My Name-PC -launch

start "" "C:\test\test1.exe" -pc My Name-PC -launch

If you won't want passing parameter and your .exe file in test folder of H: (Any Other)drive

如果您不想在 H: (Any Other) 驱动器的测试文件夹中传递参数和 .exe 文件

start "" "H:\test\test1.exe" -pc My Name-PC -launch

start "" "H:\test\test1.exe" -pc My Name-PC -launch

回答by T.Todua

/bparameter

/b范围

start /b "" "c:\program files\Microsoft Virtual PC\Virtual PC.exe" -pc "MY-PC" -launch

回答by albertein

have you tried:

你有没有尝试过:

start "c:\program files\Microsoft Virtual PC\Virtual PC.exe" "-pc MY-PC -launch"

?

?