How to capture the PID of a process when launching it from command line?

前端 未结 8 1915
栀梦
栀梦 2020-11-30 13:48

Is there a way to do this purely in a .bat file?

The purpose is to launch iexplore.exe, then kill just that instance when it\'s finished.

8条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-30 14:43

    PowerShell can be used for this:

    powershell -executionPolicy bypass -command "& {$process = start-process $args[0] -passthru -argumentlist $args[1..($args.length-1)]; exit $process.id}" notepad test.txt
    
    echo Process ID of new process: %errorlevel%
    

提交回复
热议问题