Code Monkey home page Code Monkey logo

Comments (26)

krworks avatar krworks commented on May 19, 2024 53

The correct format for this environment object is:

"environment":[{"name":"name_of_var", "value":"value_of_var"}, {"name":"var2", "value": "var2_value"}]

from vscode-cpptools.

dcsan avatar dcsan commented on May 19, 2024 23

anyone who's looking for a node example, this worked for me.

{
  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  // APPNAME=rap2 PORT=31000 DEBUG=*,-engine*,-socket.io*,-snapdragon*,-send,-express*,-nodemon*,-superagent,-AmpMetrics,-body-parser* nodemon server.js

  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Launch Program",
      "cwd": "${workspaceFolder}/server",
      "program": "${workspaceFolder}/server/server.js",
      "env":
        {
          "APPNAME": "rap2",
          "PORT": "31000"
        }
    }
  ]
}

it's not very well documented here:
https://code.visualstudio.com/docs/editor/debugging#_launch-configurations

from vscode-cpptools.

delmyers avatar delmyers commented on May 19, 2024 5

What OS are you using?

We could be clearer in the examples. The key/value pairs should go inside the array. So, something like this:

[{"name":"value", "name2":"value2"}]

Also, it looks like setting environment variables isn't working on mac.

from vscode-cpptools.

abser avatar abser commented on May 19, 2024 5
  "env":
   {
     "APPNAME": "rap2",
     "PORT": "31000"
 }

For my Java App on Mac also works like this configuration.

from vscode-cpptools.

codermannn avatar codermannn commented on May 19, 2024 4

The correct format for this environment object is:

"environment":[{"name":"name_of_var", "value":"value_of_var"}, {"name":"var2", "value": "var2_value"}]

This doesnt seem to work on mac. Property environment is not allowed.

from vscode-cpptools.

dcsan avatar dcsan commented on May 19, 2024 2

they should really document this, I find my way back here every time I try messing around with the debugger before usually giving up anyway.

from vscode-cpptools.

GPhilo avatar GPhilo commented on May 19, 2024 2

Could you please make it more explicit in the documentation that the expected format is to pass the name of the env variable and its value as values of the respective "name" and "value" keys in the json object?

The "natural" way to describe the env var to me is {"my_env_var_name": "my_value"}, not {"name": "my_env_var_name", "value": "my_value"} and using the first causes a very cryptic error message instead of something like "name key not found in environment variable specification" or something of the sort.

from vscode-cpptools.

bartekpacia avatar bartekpacia commented on May 19, 2024 2

How can I reference the env var from "env" in my "args"?

from vscode-cpptools.

NewProggie avatar NewProggie commented on May 19, 2024 1

Hey,

I have the same error on OS X (running 10.11.6), running Code Version 1.4.0. Even though I'm passing environemnt variables to the debugger (in launch.json) with

"environment": [
    {
        "name": "DYLD_FRAMEWORK_PATH",
        "value": "/my/path/here"
    },
    {
        "name": "A_VARIABLE",
        "value": "/other/stuff/here"
    }
]

it seems that the executable is run without those variable set beforehand.

Edit: My bad, it seems that in OS X lldb is started without any environment variables set, due to system protection. However, is there any way, using Visual Studio Code, to pass specific commands to the debugger, once it has been started?

For instance, on the command line I would do:

$ lldb my_executable
(lldb) env DYLD_LIBRARY_PATH=/my/foo/bar
(lldb) r

How would I achieve this, using Visual Studio Code?

Thanks in advance

from vscode-cpptools.

pieandcakes avatar pieandcakes commented on May 19, 2024 1

@dcsan If you are using node and continually running into this problem, I would suggest you file an issue in the VS Code repository as this one is for the C/C++ extension. We don't have any control over the node extension or its documentation.

from vscode-cpptools.

sean-mcmanus avatar sean-mcmanus commented on May 19, 2024 1

@GPhilo Like this microsoft/vscode-docs#4492 and #7417 ?

from vscode-cpptools.

rafaeldsousa avatar rafaeldsousa commented on May 19, 2024 1

@bartekpacia also want to know if we can actually do this. The usage of ${env:VARNAME} as suggested in docs for args doesn't seem to work. I want to be able to use ENV vars from ENV file, so that I can commit this to my repo and don't expose any sensitive information.

from vscode-cpptools.

bartekpacia avatar bartekpacia commented on May 19, 2024 1

@rafaeldsousa Apparently this is not possible. You can take a look at this issue.

from vscode-cpptools.

nebjamin99 avatar nebjamin99 commented on May 19, 2024

Ubuntu 16.04 beta 2. Thanks for clarifying. That sorted it! Works great!

from vscode-cpptools.

nebjamin99 avatar nebjamin99 commented on May 19, 2024

I reopened this issue because I was mistaken when I said that sorted it.

When specifying anything in the 'environment' tag vscode reports the following error:

error while processing request 'launch' (exception: Required property 'Value' not found in JSON. Path 'environment[0]', line 15, position 6.)

My debug launch script looks like this:

{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "C++ Launch (GDB)",
            "type": "cppdbg",
            "request": "launch",
            "launchOptionType": "Local",
            "miDebuggerPath": "/usr/bin/gdb",
            "targetArchitecture": "x64",
            "program": "/home/ben/git/server/core/build/debug/src/libcored/vca-cored-cxx-unit-tests",
            "args": [],
            "stopAtEntry": false,
            "cwd": "/home/ben/git/tool-chain/rootfs/host/ubuntu/16.04/opt/company/lib64",
            "environment": [{"name":"value"}],
        },
        {
            "name": "C++ Attach (GDB)",
            "type": "cppdbg",
            "request": "launch",
            "launchOptionType": "Local",
            "miDebuggerPath": "/usr/bin/gdb",
            "targetArchitecture": "x64",
            "program": "enter program name, for example ${workspaceRoot}/a.out",
            "args": [],
            "stopAtEntry": false,
            "cwd": "${workspaceRoot}",
            "environment": [],
            "processId": "enter program's process ID"
        }
    ]
}

If I remove the contents of environment it loads the process fine (I just can't debug it as I need to pass LD_LIBRARY_PATH for some shared lib dependencies).

from vscode-cpptools.

pieandcakes avatar pieandcakes commented on May 19, 2024

Closing as it looks like @krworks comment solves the problem

from vscode-cpptools.

dhiraj113 avatar dhiraj113 commented on May 19, 2024

This issue still seems to exist. I am unable to set LD_LIBRARY_PATH environment variable in Ubuntu 16.04.

from vscode-cpptools.

pieandcakes avatar pieandcakes commented on May 19, 2024

@nebjamin99 You can pass additional commands in the launch.json using "setupCommands". You can find more info at: https://github.com/Microsoft/vscode-cpptools/blob/master/launch.md

@dhiraj113 I noticed you opened another issue, #616. Please update that issue with the information requested.

from vscode-cpptools.

pieandcakes avatar pieandcakes commented on May 19, 2024

@lohiarahul Can you confirm that your type field in your launch.json is showing "type": "cppdbg" ? According to the package.json schema, there doesn't seem to be a restriction for Mac and I can't duplicate the error.

from vscode-cpptools.

codermannn avatar codermannn commented on May 19, 2024

't seem to be a restriction for Mac and I can't duplicate the error.

The debugging type is different. Its node. I guess it might have a different format.

from vscode-cpptools.

pieandcakes avatar pieandcakes commented on May 19, 2024

@lohiarahul Yea, This extension provides the types of cppdbg and cppvsdbg. You probably need to find the issues page for the node extension.

from vscode-cpptools.

dcsan avatar dcsan commented on May 19, 2024

also useful for node folks
https://techbrij.com/visual-studio-code-tasks-debugging

from vscode-cpptools.

947942434 avatar 947942434 commented on May 19, 2024

windows ? $env:path+=/xx/xx;/xxxx/xxx
set path=%path%;/xx/xx;/xxx/xxx
"environment":[{β€œname”:"path","value":"${path};/xx/xx;/xxx/xxx"}] ?

from vscode-cpptools.

GPhilo avatar GPhilo commented on May 19, 2024

@sean-mcmanus That's much clearer now, thank you for the quick update!

from vscode-cpptools.

mkamyab avatar mkamyab commented on May 19, 2024

This works for python as well.

anyone who's looking for a node example, this worked for me.

{
  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  // APPNAME=rap2 PORT=31000 DEBUG=*,-engine*,-socket.io*,-snapdragon*,-send,-express*,-nodemon*,-superagent,-AmpMetrics,-body-parser* nodemon server.js

  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Launch Program",
      "cwd": "${workspaceFolder}/server",
      "program": "${workspaceFolder}/server/server.js",
      "env":
        {
          "APPNAME": "rap2",
          "PORT": "31000"
        }
    }
  ]
}

it's not very well documented here:
https://code.visualstudio.com/docs/editor/debugging#_launch-configurations

from vscode-cpptools.

rafaeldsousa avatar rafaeldsousa commented on May 19, 2024

@bartekpacia I believe I was able to use a combination of envFile + some non sensitive info on env.

"envFile": "${workspaceFolder}/.env",
"env": {
.
.
.
}

from vscode-cpptools.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.