bradgonesurfing
bradgonesurfing

Reputation: 32192

Is it possible to launch a process under powershell and have visual studio immediately connect to it for debugging

I have a program foo.exe

foo.exe  sometxtfile -arg0 10 -arg1 "cats" -arg3 666

It currently crashes with an exception. I have the project in visual studio and could put that command line into the visual studio debug startup but I'd like to be more flexible and be able to start this from powershell.

I am aware of Debug-Process but that only debugs a currently running process. Would it be possible to use this to launch and debug?

Upvotes: 0

Views: 366

Answers (1)

bradgonesurfing
bradgonesurfing

Reputation: 32192

The trick is to wait for the process to start the job as a background process and then call Debug-Process on it.

start-job {
    foo.exe  sometxtfile -arg0 10 -arg1 "cats" -arg3 666
}
$process="foo"
Write-Host "Waiting for $process to start" 
Do {

    $status = Get-Process $process -ErrorAction SilentlyContinue

    If (!($status)) { 
        Write-Host -NoNewline '.' 
    }

    Else { 
        Write-Host ""  
        Write-Host "$process has started"  
        $started = $true 
    }

}
Until ( $started )

debug-process -Name ${process}

debug-process -Name ${process} 

Upvotes: 1

Related Questions