CapsAdmin
CapsAdmin

Reputation: 95

Attaching the windows debugger in VS2010 from a batch file?

Is it possible to attach the windows debugger in VS2010 to a process from a batch file?

preferably by giving it a process name

Upvotes: 2

Views: 1809

Answers (3)

Mark Wilkins
Mark Wilkins

Reputation: 41222

If you have the debugging tools for windows available, the tlist.exe utility will yield the process ID for a process name. If that is available, then the following will attach to a given process:

rem Get the process ID
for /f %%f in ('tlist -p %1') do set mypid=%%f
rem attach to it with selected debugger
vsjitDebugger -p %mypid%

Edit If tlist is not available, I think tasklist will work. It's a bit uglier, but the following worked for me (you know ... it works my on my system :) Note too that I edited the command previous example to work in a cmd.exe prompt (I use tcc, which does require as many % signs).

rem Get the process ID
for /f "tokens=2 delims= " %%f in ('tasklist /nh /fi "imagename eq %1"' ) do set mypid=%%f
rem attach to it with selected debugger
vsjitDebugger -p %mypid%

Upvotes: 2

Gabe
Gabe

Reputation: 86718

Since you presumably already have the process running, you would use vsjitdebugger.exe /p 1234 where 1234 is the PID of the process you want to debug. If you don't know it, you would have to use some other method to figure it out.

Upvotes: 2

JohnC
JohnC

Reputation: 842

Specifying a /Command switch on devenv.exe 's command-line will make it run a specified command on open. You could specify the Debug.AttachToProcess command. Don't know if you can specify a pid, though, when you execute that command.

Upvotes: 2

Related Questions