在一个 cmd
窗口,我搜索一个特定的文件,然后把它传递到一个可执行文件中。findstr …
cmd /r dir /s /b RunnerUnitTest.dll | findstr /r bin\\ > tests_list.txt
cmd /r for /f %f in (tests_list.txt) do vstest.console.exe "%f"
You can do something like this without an intermediate file, since
will return a
object for files, and
objects for directories (both of which are derived from
):
What this will do is recursively search for all files found named
with parent folders
and
, and then for each file returned (I’ve added a
to ensure we only get one assembly back but this is optional) pass the full path to the assembly to the
解决方案:
folder won’t be returned at all for execution consideration.Get-ChildItem
As an FYI, piping with FileInfo
works much in the same way as it does with other shells like DirectoryInfo
or FileSystemInfo
, but it supports passing around complex objects instead of strings. As a general rule, you can pipe any output on the
Get-ChildItem -Recurse bin\Debug\RunnerUnitTest.dll | Select-Object -First 1 | Foreach-Object {
vstest.console.exe $_.FullName
}
output streamRunnerUnitTest.dll
to other cmdlets or save the output to variables. Debug
Redirection operatorsbin
work similarly as well.Select-Object -First 1
第一个命令寻找文件,它找到了两个。vstest.console.exe
RunnerUnitTest/bin/Debug/RunnerUnitTest.dll。obj
RunnerUnitTest/obj/Debug/RunnerUnitTest.dll|
然后它将其缩小到一个(路径中的bin),并将其粘贴到一个文件中。Bash
RunnerUnitTest/bin/Debug/RunnerUnitTest.dll。cmd
第二行把这个输出作为参数传到一个可执行文件中。顺便说一下,这是为gitlab运行程序准备的。 在cmd窗口中,我搜索一个特定的文件,然后将其传递到一个可执行文件中。我想用PowerShell重做,但作为新手,我不知道该怎么做。 cmd r dir s b RunnerUnitTest.dll