visual-studiobatch-filetrx

How do I use the output file generated from a program as the input for another program? batch file


I'm running unit tests with Visual Studio which takes this as the command on the cmd:

vstest.console.exe C:\Desktop\Project\UnitTests\Debug\UnitTests.dll /Logger:trx

Once that executes it generates a .trx file (visual studio test result file). Next I want to take this file and run it through a program called trx2html that will generate a html file from it that is in a readable format. The command for this is:

trx2html.exe trxResultFile

This seems fairly simple but I can't seem to get the second part to work. My problem is that the first program generates a filename so I can't just type this filename after the trx2html.exe.

Here is my bat file so far:

@echo %1

SET ProjectPath=%1
SET VsTest=vstest.console.exe %ProjectPath% /Logger:trx
SET TestWindowPath="C:\Program Files\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow"
SET TestResults="C:\Program Files\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\TestResults\"

cd /d %TestWindowPath%

pause

%VsTest%

trx2html.exe "%TestResults% | %VsTest%"

Any help would be appreciated, thanks in advance.


Solution

  • This is the solution I used:

    cd /d %TestResults%
    
    for /f "delims=" %%x in ('dir /od /a-d /b *.*') do set RECENT=%%x
    echo %RECENT%
    
    SET trx=trx2html.exe "%RECENT%"
    
    %trx%
    

    and the whole program:

    @echo %1
    
    SET ProjectPath=%1
    SET VsTest=vstest.console.exe %ProjectPath% /Logger:trx
    
    
    SET TestWindowPath="C:\Program Files\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow"
    
    SET TestResults=C:\Program Files\Microsoft Visual Studio 12.0\Common7\IDE\CommonExtensions\Microsoft\TestWindow\TestResults\
    
    cd /d %TestWindowPath%
    
    %VsTest%
    
    cd /d %TestResults%
    
    for /f "delims=" %%x in ('dir /od /a-d /b *.*') do set RECENT=%%x
    echo %RECENT%
    
    SET trx=trx2html.exe "%RECENT%"
    
    %trx%