Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Debugging: Attach to Process for Console App running inside cmd.exe

How do you "Attach to Process..." for a console application thats running from a CMD window and not launched by F5? The reason I ask is because the application takes command line arguments and I want to have a genuine experience.

I've even attaching to CMD.exe, but no luck, or setting a break-point using Console.ReadKey() with also no luck. I'm kind of at a loss here.

Is this possible?

like image 852
Chris Avatar asked May 03 '10 21:05

Chris


People also ask

How do I Debug a console application?

Press F5 to run the program in Debug mode. Another way to start debugging is by choosing Debug > Start Debugging from the menu. Enter a string in the console window when the program prompts for a name, and then press Enter . Program execution stops when it reaches the breakpoint and before the Console.

How do I Debug command prompt in Visual Studio?

In Visual Studio 2010, right click the project, choose Properties, click the configuring properties section on the left pane, then click Debugging, then on the right pane there is a box for command arguments. In that enter the command line arguments. You are good to go. Now debug and see the result.


2 Answers

You have some options:

  • Use "Debug -> Command line arguments" option in Visual Studio;
  • Use "Debug -> Attach to process" and find your process; it is not cmd.exe, but a process with executable name like "MyProject.exe". You can use Process Explorer or another task manager with "tree view" support to easily find the Process ID - just look for the processes started by your cmd.exe.
  • Put Debugger.Break() into your code - when this method is executed, the system will launch a dialog asking you to choose what instance of Visual Studio to use for debugging (you can choose the one with your project already open).
like image 139
VladV Avatar answered Sep 21 '22 14:09

VladV


To debug from the command line rather than using the VS GUI maze:

  • Launch the Visual Studio Command Prompt

  • type vsjitdebugger/? which gives you the command example like :

c:> vsjitdebugger [AppName] [Args] : Launch the specified executable and attach to debugger

  • typing tlist or tasklist will give you PIDs for attaching to existing processes. example:

c:> tasklist | find /i "web"

like image 30
Kwame Avatar answered Sep 21 '22 14:09

Kwame