windows 在命令提示符下运行 .exe 的 Bat 文件

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

Bat file to run a .exe at the command prompt

windowsbatch-fileexe

提问by abatishchev

I want to create a .bat file so I can just click on it so it can run:

我想创建一个 .bat 文件,这样我只需点击它就可以运行:

svcutil.exe /language:cs /out:generatedProxy.cs /config:app.config http://localhost:8000/ServiceModelSamples/service

Can someone help me with the structure of the .bat file?

有人可以帮助我了解 .bat 文件的结构吗?

回答by abatishchev

To start a program and then close command prompt without waiting for program to exit:

要启动程序然后关闭命令提示符而不等待程序退出:

start /d "path" file.exe

回答by user2075928

You can use:

您可以使用:

start "windowTitle" fullPath/file.exe

Note: the first set of quotes must be there but you don't have to put anything in them, e.g.:

注意:第一组引号必须存在,但您不必在其中添加任何内容,例如:

start "" fullPath/file.exe

回答by shinukb

it is very simple code for executing notepad bellow code type into a notepad and save to extension .bat Exapmle:notepad.bat

这是一个非常简单的代码,用于将记事本波纹管代码类型执行到记事本中并保存到扩展名 .bat Exapmle:notepad.bat

start "c:\windows\system32" notepad.exe   

(above code "c:\windows\system32" is path where you kept your .exe program and notepad.exe is your .exe program file file)

(上面的代码“c:\windows\system32”是您保存 .exe 程序的路径,notepad.exe 是您的 .exe 程序文件文件)

enjoy!

请享用!

回答by GavinCattell

Just put that line in the bat file...

只需将该行放在bat文件中...

Alternatively you can even make a shortcut for svcutil.exe, then add the arguments in the 'target' window.

或者,您甚至可以为 svcutil.exe 创建一个快捷方式,然后在“目标”窗口中添加参数。

回答by MBoy

A bat file has no structure...it is how you would type it on the command line. So just open your favourite editor..copy the line of code you want to run..and save the file as whatever.bat or whatever.cmd

bat 文件没有结构……这就是您在命令行上键入它的方式。所以只需打开你最喜欢的编辑器..复制你想要运行的代码行..并将文件保存为whatever.bat或whatever.cmd

回答by myplacedk

Just stick in a file and call it "ServiceModelSamples.bat" or something.

只需插入一个文件并将其命名为“ServiceModelSamples.bat”或其他名称。

You could add "@echo off" as line one, so the command doesn't get printed to the screen:

您可以将“@echo off”添加为第一行,这样命令就不会打印到屏幕上:

@echo off
svcutil.exe /language:cs /out:generatedProxy.cs /config:app.config http://localhost:8000/ServiceModelSamples/service

回答by k?e?m?p? ?

If you want to be real smart, at the command line type:

如果你想变得真正聪明,在命令行输入:

echo svcutil.exe /language:cs /out:generatedProxy.cs /config:app.config http://localhost:8000/ServiceModelSamples/service >CreateService.cmd

echo svcutil.exe /language:cs /out:generatedProxy.cs /config:app.config http://localhost:8000/ServiceModelSamples/service >CreateService.cmd

Then you have CreateService.cmdthat you can run whenever you want (.cmdis just another extension for .batfiles)

然后你就CreateService.cmd可以随时随地运行(.cmd只是.bat文件的另一个扩展名)

回答by Simon

What's stopping you?

是什么阻止你?

Put this command in a text file, save it with the .bat (or .cmd) extension and double click on it...

将此命令放入文本文件中,使用 .bat(或 .cmd)扩展名保存并双击它...

Presuming the command executes on your system, I think that's it.

假设命令在您的系统上执行,我认为就是这样。

回答by Gipphe

As described here, about the Startcommand, the following would start your application with the parameters you've specified:

如上所述这里,有关Start命令,下面就开始与您指定的参数,您的应用程序:

start "svcutil" "svcutil.exe" "language:cs" "out:generatedProxy.cs" "config:app.config" "http://localhost:8000/ServiceModelSamples/service"
  • "svcutil", after the startcommand, is the name given to the CMD window upon running the application specified. This is a required parameter of the startcommand.

  • "svcutil.exe"is the absolute or relative path to the application you want to run. Using quotation marks allows you to have spaces in the path.

  • After the application to start has been specified, all the following parameters are interpreted as arguments sent to the application.

  • "svcutil"start命令之后,是在运行指定的应用程序时为 CMD 窗口指定的名称。这是start命令的必需参数。

  • "svcutil.exe"是您要运行的应用程序的绝对或相对路径。使用引号允许您在路径中有空格。

  • 指定要启动的应用程序后,以下所有参数都被解释为发送到应用程序的参数。

回答by Mark

If your folders are set to "hide file extensions", you'll name the file *.bat or *.cmd and it will still be a text file (hidden .txt extension). Be sure you can properly name a file!

如果您的文件夹设置为“隐藏文件扩展名”,您将文件命名为 *.bat 或 *.cmd,它仍然是一个文本文件(隐藏的 .txt 扩展名)。确保您可以正确命名文件!