Find out process ID of nunit of particular instance












0















I have three batch files, each opening one instance of NUnit. I want to kill a particular instance of NUnit when the tests are completed. I am able to fetch the three process ID's for three NUnit instances.



But is there a way to find out which processId corresponds to which Nunit instance?



Check the image below.



enter image description here



Here it is showing me process ID. But cannot recognize which one is for which instance.



Here is my code in batch for killing the NUnit process ID.



for /F "tokens=1,2,*" %%a in ('tasklist /FI "IMAGENAME eq nunit.exe"') do (
SETLOCAL ENABLEDELAYEDEXPANSION
set PID=%%b
echo PID StartRun_XXX=!PID!)

::echo before loop
:: Check for TestResult.xml file generation.
:: at the moment when TestResult.xml generated, kill the NUNIT instance and subsequently call OverViewGenerator.bat to generate TestResult.htm


pause
:loop
if exist %~dp0TestResult_%TestCategory%_%TimeStamp%.xml (
cd %~dp0
echo ====================inside if exist------dp0=%~dp0===================
pause
echo PID=!PID!
taskkill /PID !PID! /T


This code abruptly kills any nunit instance.










share|improve this question

























  • The for loop will overwrite the PID with all found nunit PIDs, so only the last one persists. In the if code block taskkill will only kill this last one PID.

    – LotPings
    Nov 26 '18 at 11:57











  • Why not check the PID's before and after each instance? then you can determine which PID belongs to which respective instance before deciding which to kill.

    – Compo
    Nov 26 '18 at 13:58
















0















I have three batch files, each opening one instance of NUnit. I want to kill a particular instance of NUnit when the tests are completed. I am able to fetch the three process ID's for three NUnit instances.



But is there a way to find out which processId corresponds to which Nunit instance?



Check the image below.



enter image description here



Here it is showing me process ID. But cannot recognize which one is for which instance.



Here is my code in batch for killing the NUnit process ID.



for /F "tokens=1,2,*" %%a in ('tasklist /FI "IMAGENAME eq nunit.exe"') do (
SETLOCAL ENABLEDELAYEDEXPANSION
set PID=%%b
echo PID StartRun_XXX=!PID!)

::echo before loop
:: Check for TestResult.xml file generation.
:: at the moment when TestResult.xml generated, kill the NUNIT instance and subsequently call OverViewGenerator.bat to generate TestResult.htm


pause
:loop
if exist %~dp0TestResult_%TestCategory%_%TimeStamp%.xml (
cd %~dp0
echo ====================inside if exist------dp0=%~dp0===================
pause
echo PID=!PID!
taskkill /PID !PID! /T


This code abruptly kills any nunit instance.










share|improve this question

























  • The for loop will overwrite the PID with all found nunit PIDs, so only the last one persists. In the if code block taskkill will only kill this last one PID.

    – LotPings
    Nov 26 '18 at 11:57











  • Why not check the PID's before and after each instance? then you can determine which PID belongs to which respective instance before deciding which to kill.

    – Compo
    Nov 26 '18 at 13:58














0












0








0


0






I have three batch files, each opening one instance of NUnit. I want to kill a particular instance of NUnit when the tests are completed. I am able to fetch the three process ID's for three NUnit instances.



But is there a way to find out which processId corresponds to which Nunit instance?



Check the image below.



enter image description here



Here it is showing me process ID. But cannot recognize which one is for which instance.



Here is my code in batch for killing the NUnit process ID.



for /F "tokens=1,2,*" %%a in ('tasklist /FI "IMAGENAME eq nunit.exe"') do (
SETLOCAL ENABLEDELAYEDEXPANSION
set PID=%%b
echo PID StartRun_XXX=!PID!)

::echo before loop
:: Check for TestResult.xml file generation.
:: at the moment when TestResult.xml generated, kill the NUNIT instance and subsequently call OverViewGenerator.bat to generate TestResult.htm


pause
:loop
if exist %~dp0TestResult_%TestCategory%_%TimeStamp%.xml (
cd %~dp0
echo ====================inside if exist------dp0=%~dp0===================
pause
echo PID=!PID!
taskkill /PID !PID! /T


This code abruptly kills any nunit instance.










share|improve this question
















I have three batch files, each opening one instance of NUnit. I want to kill a particular instance of NUnit when the tests are completed. I am able to fetch the three process ID's for three NUnit instances.



But is there a way to find out which processId corresponds to which Nunit instance?



Check the image below.



enter image description here



Here it is showing me process ID. But cannot recognize which one is for which instance.



Here is my code in batch for killing the NUnit process ID.



for /F "tokens=1,2,*" %%a in ('tasklist /FI "IMAGENAME eq nunit.exe"') do (
SETLOCAL ENABLEDELAYEDEXPANSION
set PID=%%b
echo PID StartRun_XXX=!PID!)

::echo before loop
:: Check for TestResult.xml file generation.
:: at the moment when TestResult.xml generated, kill the NUNIT instance and subsequently call OverViewGenerator.bat to generate TestResult.htm


pause
:loop
if exist %~dp0TestResult_%TestCategory%_%TimeStamp%.xml (
cd %~dp0
echo ====================inside if exist------dp0=%~dp0===================
pause
echo PID=!PID!
taskkill /PID !PID! /T


This code abruptly kills any nunit instance.







batch-file nunit taskkill






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 26 '18 at 13:47









freedomn-m

13.3k32148




13.3k32148










asked Nov 26 '18 at 11:31









Karthik SaxenaKarthik Saxena

4410




4410













  • The for loop will overwrite the PID with all found nunit PIDs, so only the last one persists. In the if code block taskkill will only kill this last one PID.

    – LotPings
    Nov 26 '18 at 11:57











  • Why not check the PID's before and after each instance? then you can determine which PID belongs to which respective instance before deciding which to kill.

    – Compo
    Nov 26 '18 at 13:58



















  • The for loop will overwrite the PID with all found nunit PIDs, so only the last one persists. In the if code block taskkill will only kill this last one PID.

    – LotPings
    Nov 26 '18 at 11:57











  • Why not check the PID's before and after each instance? then you can determine which PID belongs to which respective instance before deciding which to kill.

    – Compo
    Nov 26 '18 at 13:58

















The for loop will overwrite the PID with all found nunit PIDs, so only the last one persists. In the if code block taskkill will only kill this last one PID.

– LotPings
Nov 26 '18 at 11:57





The for loop will overwrite the PID with all found nunit PIDs, so only the last one persists. In the if code block taskkill will only kill this last one PID.

– LotPings
Nov 26 '18 at 11:57













Why not check the PID's before and after each instance? then you can determine which PID belongs to which respective instance before deciding which to kill.

– Compo
Nov 26 '18 at 13:58





Why not check the PID's before and after each instance? then you can determine which PID belongs to which respective instance before deciding which to kill.

– Compo
Nov 26 '18 at 13:58












1 Answer
1






active

oldest

votes


















1














Your best bet is probably distinguishing nunit processes when they are launched.



It is possible to obtain PID of a process started through WMIC:



set "tab="  <<<<<<<<<<<< PLEASE insert TAB after '=' 
set "pid="
for /F "usebackq tokens=1,2 delims=;=%tab% " %%i in (
`wmic process call create "nunit.exe"^, "C:workingdir"`
) do if %%j gtr 0 set pid=%%j


(copied from this answer)



Then you can save PID into a file



echo set "PID=%pid%" >yourfile.bat


To kill the process just run the script to obtain the variable



call yourfile.bat
taskkill /pid %pid%
taskkill /f /pid %pid%
del /y yourfile.bat




See also: How to get the output of "wmic process call create"






share|improve this answer
























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53480186%2ffind-out-process-id-of-nunit-of-particular-instance%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Your best bet is probably distinguishing nunit processes when they are launched.



    It is possible to obtain PID of a process started through WMIC:



    set "tab="  <<<<<<<<<<<< PLEASE insert TAB after '=' 
    set "pid="
    for /F "usebackq tokens=1,2 delims=;=%tab% " %%i in (
    `wmic process call create "nunit.exe"^, "C:workingdir"`
    ) do if %%j gtr 0 set pid=%%j


    (copied from this answer)



    Then you can save PID into a file



    echo set "PID=%pid%" >yourfile.bat


    To kill the process just run the script to obtain the variable



    call yourfile.bat
    taskkill /pid %pid%
    taskkill /f /pid %pid%
    del /y yourfile.bat




    See also: How to get the output of "wmic process call create"






    share|improve this answer




























      1














      Your best bet is probably distinguishing nunit processes when they are launched.



      It is possible to obtain PID of a process started through WMIC:



      set "tab="  <<<<<<<<<<<< PLEASE insert TAB after '=' 
      set "pid="
      for /F "usebackq tokens=1,2 delims=;=%tab% " %%i in (
      `wmic process call create "nunit.exe"^, "C:workingdir"`
      ) do if %%j gtr 0 set pid=%%j


      (copied from this answer)



      Then you can save PID into a file



      echo set "PID=%pid%" >yourfile.bat


      To kill the process just run the script to obtain the variable



      call yourfile.bat
      taskkill /pid %pid%
      taskkill /f /pid %pid%
      del /y yourfile.bat




      See also: How to get the output of "wmic process call create"






      share|improve this answer


























        1












        1








        1







        Your best bet is probably distinguishing nunit processes when they are launched.



        It is possible to obtain PID of a process started through WMIC:



        set "tab="  <<<<<<<<<<<< PLEASE insert TAB after '=' 
        set "pid="
        for /F "usebackq tokens=1,2 delims=;=%tab% " %%i in (
        `wmic process call create "nunit.exe"^, "C:workingdir"`
        ) do if %%j gtr 0 set pid=%%j


        (copied from this answer)



        Then you can save PID into a file



        echo set "PID=%pid%" >yourfile.bat


        To kill the process just run the script to obtain the variable



        call yourfile.bat
        taskkill /pid %pid%
        taskkill /f /pid %pid%
        del /y yourfile.bat




        See also: How to get the output of "wmic process call create"






        share|improve this answer













        Your best bet is probably distinguishing nunit processes when they are launched.



        It is possible to obtain PID of a process started through WMIC:



        set "tab="  <<<<<<<<<<<< PLEASE insert TAB after '=' 
        set "pid="
        for /F "usebackq tokens=1,2 delims=;=%tab% " %%i in (
        `wmic process call create "nunit.exe"^, "C:workingdir"`
        ) do if %%j gtr 0 set pid=%%j


        (copied from this answer)



        Then you can save PID into a file



        echo set "PID=%pid%" >yourfile.bat


        To kill the process just run the script to obtain the variable



        call yourfile.bat
        taskkill /pid %pid%
        taskkill /f /pid %pid%
        del /y yourfile.bat




        See also: How to get the output of "wmic process call create"







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 26 '18 at 23:28









        Jack WhiteJack White

        33416




        33416
































            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53480186%2ffind-out-process-id-of-nunit-of-particular-instance%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Costa Masnaga

            Fotorealismo

            Sidney Franklin