vscode-cpptools icon indicating copy to clipboard operation
vscode-cpptools copied to clipboard

Support "Run without debugging"

Open HorstBaerbel opened this issue 7 years ago • 51 comments

I'm running VSCode 1.17.02 on Ubuntu 16.04 x64 and cpptools 0.14.

Could you please add information about how to launch an application w/o debugging (CTRL+F5) to the VSCode C++ docs and maybe post a complete tasks.json / launch.json example here? I've read a couple of issues now and can't quite make launching work... I use make to build my projects. I put

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Launch",
            "runtimeExecutable": "MYEXECUTABLE",
            "program": "${workspaceRoot}/MYOUTPUT.FILE",
            "preLaunchTask": "Make"
            }
    ]
}

into launch.json. My tasks.json looks like this:

{
    "version": "2.0.0",
    "tasks": [
        {
            "taskName": "Make",
            "type": "shell",
            "command": "make",
            "args": [""],
            "group": "build",
            "presentation": {
                "reveal": "always",
                "panel": "dedicated"
            },
            "problemMatcher": {
                "owner": "cpp",
                "fileLocation": ["relative", "${workspaceRoot}"],
                "pattern": {
                    "regexp": "^(.*):(\\d+):(\\d+):\\s+(warning|error):\\s+(.*)$",
                    "file": 1,
                    "line": 2,
                    "column": 3,
                    "severity": 4,
                    "message": 5
                }
            }
        }
    ]
}

The binary file is built successfully via CTRL+SHIFT+B, but when launching via CTRL+F5 I get the message "No executable targets are available". I guess vscode does not know what output file make generates...

HorstBaerbel avatar Nov 03 '17 12:11 HorstBaerbel

Just create another task that runs builds and runs executable :|

agauniyal avatar Nov 03 '17 14:11 agauniyal

And connect that to CTRL+F5 through the key bindings? Might work, but how is it actually meant to be done?! What about my launch.json example? Should that work? Why not? The docs are lacking there imo... :/

HorstBaerbel avatar Nov 03 '17 16:11 HorstBaerbel

No you cannot connect it to CTRL + F5 but you'd be able to run it with CTRL+SHIFT+B if you set it default build task which I've done :)

agauniyal avatar Nov 03 '17 18:11 agauniyal

Thanks for the workaround, but I suspect there must be an actual solution to the problem...

HorstBaerbel avatar Nov 03 '17 20:11 HorstBaerbel

@HorstBaerbel We haven't implemented Launch without Debugging. I'll mark this as a feature request but you may either do it as @agauniyal suggested with a batch file or from the Terminal within VSCode.

pieandcakes avatar Nov 06 '17 19:11 pieandcakes

Thanks. Will try the "build-and-run" version then for the moment...

HorstBaerbel avatar Nov 07 '17 20:11 HorstBaerbel

I would also love to see a Launch Without Debugging feature added to vscode.

jcrawford avatar Sep 18 '18 12:09 jcrawford

In some cases, you can use Code Runner an alternative.

chuxubank avatar Sep 18 '18 12:09 chuxubank

Isn't CTRL+F5 already the default key binding for Start (without debugging) (workbench.action.debug.run)? ~It seems to work for me out of the box too: F5 launches with debugging, CTRL+F5 launches without.~

EDIT: In my case I don't think debugging is actually ever running properly, but at least CTRL+F5 is still "running without debugging". The only difference I see is that the call stack shows threads when I F5 but not when I CTRL+F5...

Visual Studio Code Default Key Bindings: https://code.visualstudio.com/docs/getstarted/keybindings#_debug

My launch.json file:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "(Windows) Launch",
            "type": "cppvsdbg",
            "request": "launch",
            "program": "${workspaceFolder}/bin/main.exe",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceFolder}/data/",
            "environment": [],
            "externalConsole": true,
        }
    ]
}

My tasks.json file:

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "build",
            "type": "shell",
            "command": "g++",
            "args": [
                "-g", "${workspaceFolder}/src/main.cpp", "-o", "${workspaceFolder}/bin/main.exe"
            ],
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}

My version of VS Code:

Version: 1.27.1 (system setup)
Commit: 5944e81f3c46a3938a82c701f96d7a59b074cfdc
Date: 2018-09-06T09:21:18.328Z
Electron: 2.0.7
Chrome: 61.0.3163.100
Node.js: 8.9.3
V8: 6.1.534.41
Architecture: x64

swharden avatar Sep 28 '18 21:09 swharden

@pieandcakes maybe a week ago, Ctrl+F5 do the same with Start without debugging. Don't why doesn't work now.

roachsinai avatar Jan 18 '19 10:01 roachsinai

@roachsinai We haven't done work enable that scenario and we haven't shipped an extension update since 0.20.1 which shipped a few months back. Did you apply a VS Code update?

pieandcakes avatar Jan 18 '19 17:01 pieandcakes

Yes, update it at 2019-01-09...

roachsinai avatar Jan 18 '19 18:01 roachsinai

Needing this launch feature.

xgdgsc avatar Aug 29 '19 12:08 xgdgsc

We need this to run external application and capture the stdout, with no debug attached.

polyclash avatar Aug 29 '19 15:08 polyclash

@polyclash @xgdgsc for now you can use the VS Code Terminal window to launch your application from the command line.

pieandcakes avatar Aug 29 '19 18:08 pieandcakes

@pieandcakes yes, I use a task, the internal terminal is configured with bash(mingw64), but the terminal don't receive the stdout from the application.

polyclash avatar Aug 30 '19 11:08 polyclash

But then I have to set environment variables again in the terminal, I already set those in launch configurations.

xgdgsc avatar Aug 31 '19 00:08 xgdgsc

Looking forward to this feature.

duanyongli avatar Dec 26 '19 03:12 duanyongli

Also waiting for this feature.

voltflake avatar Feb 13 '20 13:02 voltflake

One more vote. Setting all environment vars, launch arguments with unit test filters etc again separately is quite annoying. Debuggers start really slowly in larger projects, due to big symbol tables, being able to make minor edits to code and hit Ctrl+F5 to trigger rebuild and run would really speed iterations.

kaidokert avatar Mar 04 '20 20:03 kaidokert

Another vote. I am writing performance-critical code and I often want to benchmark runtime in release mode. The command line arguments I specify in launch.json are not passed to the command.

jfostier avatar Mar 05 '20 08:03 jfostier

+1, I want to reuse args from launch.json. Also enable to start from the terminal.

rido-min avatar Mar 06 '20 02:03 rido-min

Is this implemented yet?

fufjvnvnf avatar May 03 '20 04:05 fufjvnvnf

+1

qalisander avatar May 04 '20 01:05 qalisander

@fufjvnvnf No.

sean-mcmanus avatar May 04 '20 21:05 sean-mcmanus

+1

jan-runkel-zeitgleich avatar May 20 '20 13:05 jan-runkel-zeitgleich

Has there been any progress on this? This is a very nice feature to have.

AVSurfer123 avatar Jan 22 '21 21:01 AVSurfer123

My scenario is that I use compounds to launch client and server executables and debug them both at the same time. Command-line arguments are sometimes long and verbose for configuring various debug environments. For most cases this is great.

However, they both share a lot of the same library code and sometimes I need breakpoints to only trigger for one process and the other process interferes, making debugging slow.

Support for run without debugging with be perfect here.

Meanwhile, I'm using the fact that VSCode currently doesn't debug child processes, creating a forwarding executable that launches the target and exits immediately:


#include <Shlwapi.h>
#include <stdio.h>
#include <windows.h>

#pragma comment(lib, "shlwapi.lib")

int main(int argc, const char* argv[])
{
    // Header
    printf("Forwarder.exe Running...\n\n");
    if (argc < 2)
    {
        printf("ERROR: Not enough arguments provided\n");
        return 1;
    }

    // Get target executable
    const char* executable = argv[1];
    printf("Executable to Launch  : %s\n", executable);
    if (!PathFileExists(executable))
    {
        printf("ERROR: Executable path doesn't exist\n");
        return 1;
    }

    // Parse command line for forwarding
    const char* command_line = GetCommandLine();
    printf("Command Line          : %s\n", command_line);
    const char* arguments = PathGetArgs(command_line);
    printf("Forwarder Arguments   : %s\n", arguments);
    const char* forward_arguments = PathGetArgs(arguments);
    printf("Arguments to forward  : %s\n\n", forward_arguments);

    // Launch and forward, exiting immediately
    STARTUPINFO si{};
    si.cb = sizeof(si);
    PROCESS_INFORMATION pi{};
    if (CreateProcess(executable, (char*)forward_arguments, nullptr, nullptr, FALSE, 0, nullptr, nullptr, &si, &pi) == FALSE)
    {
        printf("ERROR: Failed to create process\n");
        return 1;
    }

    printf("Success\n");

    return 0;
}

I would love to be able to delete this :)

dwilliamson avatar Mar 10 '21 09:03 dwilliamson

I don't get it. VSCode seems so complicated, with these json configurations to launch. Isn't it possible to tell vscode to run some executable when hitting ctrl+f5, without an attached debugger? I can't even figure out how to set up two launch configurations, and tell VSCode to run one for ctrl+f5 and the other for f5.

The makefile tools extension sets up a play and a debug button, but there doesn't seem to be an obvious way to configure these, and to connect them to the f5 and ctrl-f5 shortcuts.

ant6n avatar Jun 02 '21 22:06 ant6n

"Run without debugging" not working and also devices are not being listed in VS code while if we write and run command in command line then flutter application is compiled. Its weird with VSCode now, it was working well earlier. any suggestion will be welcomed. Thanks.

kamleshwebtech avatar Aug 19 '21 11:08 kamleshwebtech