简体   繁体   English

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

[英]Bat file to run a .exe at the command prompt

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 文件的结构吗?

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

start /d "path" file.exe

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, eg:注意:第一组引号必须存在,但您不必在其中添加任何内容,例如:

start "" fullPath/file.exe

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!请享用!

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 创建一个快捷方式,然后在“目标”窗口中添加参数。

A bat file has no structure...it is how you would type it on the command line. bat 文件没有结构……这就是您在命令行上键入它的方式。 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所以只需打开你最喜欢的编辑器..复制你想要运行的代码行..并将文件保存为whatever.bat或whatever.cmd

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

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

Then you have CreateService.cmd that you can run whenever you want ( .cmd is just another extension for .bat files)然后你有CreateService.cmd ,你可以随时运行( .cmd只是.bat文件的另一个扩展名)

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.假设命令在您的系统上执行,我认为就是这样。

As described here , about the Start command, 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 start command, is the name given to the CMD window upon running the application specified. "svcutil"start命令之后,是在运行指定的应用程序时为 CMD 窗口指定的名称。 This is a required parameter of the start command.这是start命令的必需参数。

  • "svcutil.exe" is the absolute or relative path to the application you want to run. "svcutil.exe"是您要运行的应用程序的绝对或相对路径。 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.指定要启动的应用程序后,以下所有参数都被解释为发送到应用程序的参数。

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).如果您的文件夹设置为“隐藏文件扩展名”,您将文件命名为 *.bat 或 *.cmd,它仍然是一个文本文件(隐藏的 .txt 扩展名)。 Be sure you can properly name a file!确保您可以正确命名文件!

Well, the important point it seems here is that svcutil is not available by default from command line, you can run it from the vs xommand line shortcut but if you make a batch file normally that wont help unless you run the vcvarsall.bat file before the script.好吧,这里似乎重要的一点是 svcutil 在命令行中默认不可用,您可以从 vs xommand 行快捷方式运行它,但是如果您通常制作一个批处理文件,除非您之前运行 vcvarsall.bat 文件,否则将无济于事剧本。 Below is a sample下面是一个示例

"C:\Program Files\Microsoft Visual Studio *version*\VC\vcvarsall.bat"
svcutil.exe /language:cs /out:generatedProxy.cs /config:app.config http://localhost:8000/ServiceModelSamples/service

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM