简体   繁体   English

如何从批处理文件运行Visual Studio exe

[英]How to run visual studio exe from batch file

My script is as below: 我的脚本如下:

for %%i in (*.mudp) do echo %%i >> test.txt
@ECHO OFF
SETLOCAL
:: remove variables starting $
FOR  /F "delims==" %%i In ('set $ 2^>Nul') DO SET "%%i="

FOR /f "delims=" %%i IN (test.txt) DO SET $%%i=Y
(FOR  /F "delims=$=" %%i In ('set $ 2^>Nul') DO ECHO %%i)>test.txt

 for /f %%C in ('Find /V /C "" ^< test.txt') do set Count=%%C
  echo The file has %Count% lines.
@echo off
cd "C:\Users\gbyraiah\pcap\createPcap\Debug"
start createPcap.exe %Count% 
exit

I am listing all text files with .mudp extension in the current directory to a test.txt file in Windows. 我将当前目录中所有扩展名为.mudp文本文件.mudp为Windows中的test.txt文件。

Then counting the number of files in the list and so I get Count value of 2 if 2 .mudp files are found. 然后计算列表中的文件Count ,如果找到2个.mudp文件,则Count值为2

Then I want to open Visual Studio .exe , loop the .exe to run it the number of times equal to Count and also pass count as a command line argument to the exe. 然后,我想打开Visual Studio .exe ,循环该.exe以使其运行等于Count的次数,并将count作为命令行参数传递给该exe。

So here my issue is I am not able to run the .exe and so neither I am able to loop. 因此,这里的问题是我无法运行.exe ,因此也无法循环。

Simply write yourExecutable.exe to start it; 只需编写yourExecutable.exe即可启动它; write yourExecutable.exe 1 to pass over the argument 1 . 编写yourExecutable.exe 1来传递参数1

To do that in a loop using arguments from 1 up to the value of %Count% , do this: 要使用从1%Count%的值的循环循环执行此操作,请执行以下操作:

for /L %%J in (1,1,%Count%) do yourExecutable.exe %%J

The start command should not be necessary for running your .exe at all. 完全不需要运行start命令即可运行.exe Regard that start runs the .exe in a new process, so the batch script does not wait for the .exe to be finished, unless you provide the switch /WAIT (like start "" /WAIT yourExecutable.exe ; "" is the title of a new window that might be opened, which should always be specified to avoid trouble with quotation of paths). 考虑到start在新进程中运行.exe ,所以批处理脚本不会等待.exe完成,除非您提供了/WAIT开关(例如start "" /WAIT yourExecutable.exe ; ""为标题可能会打开的新窗口的位置,应始终指定该窗口以避免引用路径带来麻烦。

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

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