How to escape a comma in json passed as args in a VSCode launcher.json command? - flutter

I would like to debug an APP and need to pass a in-line json as arg.
I did the following:
"configurations": [
{
"name": "app DEV",
"program": "lib/main.dart",
"request": "launch",
"type": "dart",
"args": [
"--dart-define=APP_BACKENDS={[{\"id\":\"default\",\"url\":\"https://localhost\",\"port\": \"8080\"},]}",
]
}
but the APP_BACKENDS const value is getting stripped in the first comma. lock the print of it: {[{"id":"default"
just to be clear. that is the way I'm getting the value I've printed:
static const _APP_BACKENDS =
String.fromEnvironment('APP_BACKENDS', defaultValue: '{}');

After going through a lot of links and reading, finally I found a GitHub issue https://github.com/microsoft/vscode/issues/98471 which solved my similar problem. If you go through the link and read the second last comment it explains the things regarding shell quoting.
"configurations": [
{
"name": "app DEV",
"program": "lib/main.dart",
"request": "launch",
"type": "dart",
"args": [
"--dart-define=APP_BACKENDS={[{\"id\":\"default\",\"url\":\"https://localhost\",\"port\": \"8080\"},]}",
],
"argsExpansion": "none"
}
"argsExpansion": "none" after adding this to my launch.json file I was able to run the code without adding extra \ or spaces as mentioned in other answers. I tried searching for this configuration in vscode docs but did not find any reference, however it worked for me.

I had the same issue - trying to pass a json string as a command line arg to a python script. Works fine from shell, but couldn't do the same from launch.json. VS Code was intepreting the commas as multiple arguments and passing multiple -b args into my program (4x separate -b args in my case).
Answer: add a space " " to the end of the arg value.
I fail to understand why this works, but it does. Note I'm single-slash escaping the double-quotes.
{
"name": "Test my python code",
"type": "python",
"request": "launch",
"program": "${file}",
"args": [
"-r=/store/purchase",
"-b={\"items\":[\"cake\",\"coffee\",\"toilet roll\",\"masks\"]} "
],
"console": "integratedTerminal"
},

After reading this documentation: Launch JSON Reference, specifically
this reference, I got to know that, you need to use \\\ to achieve what you want. For example. In the documentation only this is given
JSON array of command-line arguments to pass to the program when it is launched. Example ["arg1", "arg2"]. If you are escaping characters, you will need to double escape them. For example, ["{\\\"arg1\\\": true}"] will send {"arg1": true} to your application
So, after looking at this, you must pass your JSON to your args in a proper format
args: [
"--dart-define=APP_BACKENDS={[{\\\"id\\\":\\\"default\\\",\\\"url\\\":\\\"https://localhost\\\",\\\"port\\\": \\\"8080\\\"}]}"
]
This will do your job!

Related

Piping VSCode output to another program

Frustratingly there is an old issue that has been closed in relation to this. The linked issues seem to resolve this for python extensions, but I am using Typescript. No comments on it being resolved in general when it was closed so I assume that there must be a way to achieve this.
I wish to use VSCode debugging with individual test files, but also pipe the final output to a different program. VSCode escapes the pipe operator...
launch.json
{
"type": "node",
"request": "launch",
"name": "tap-single",
"skipFiles": [
"<node_internals>/**",
"${workspaceFolder}/node_modules/**"
],
"program": "${file}",
"runtimeExecutable": "/home/user/.npm-global/bin/ts-node",
"runtimeArgs": [
"--transpileOnly",
],
"args": [
"|", // This is output as `\|` in the console...
"tap-arc"
],
"console": "integratedTerminal",
}
Partial output is below;
... /home/user/.npm-global/bin/ts-node --transpileOnly ./test/example.test.ts \| tap-arc
Debugger attached.

VS Code launch.json special symbols in args

How can i pass literal string to "args" section in launch.json console .net core app? The problem is with symbols '<' and '>'.
This is part of my launch.json file:
"configurations": [
{
"name": ".NET Core Launch (console)",
"type": "coreclr",
"request": "launch",
"preLaunchTask": "build",
"program": "${workspaceFolder}/FileExtender/bin/Debug/net6.0/FileExtender.dll",
"args": [
"${workspaceFolder}\\UploadedHtml\\invoice-html-example.html",
"${workspaceFolder}\\UploadedHtml\\extend_section.html",
"</body>",
"true"
],
"cwd": "${workspaceFolder}",
"stopAtEntry": false,
"console": "internalConsole"
},
I'm trying to pass string "</body>" literally to the program args, but VS Code says: "input or output cannot be redirected because the specified file is invalid".
If i use escape characters like this "\<\/body\>" then VS code underlines it as "Invalid escape character in string". However the Program is started, but in the args i get "/body". Symbols '<' and '>' disappear somewhere. Same happens if i use \\\ as escape chars.

(tasks.json) I can't figure out how to use escaping characters using WSL as a shell

I'm running VSCode 1.54.3 on Windows10 along with Ubuntu in WSL.
This is the task I'm trying to build.
{
"label": "Verilog: Compile iVerilog File ",
"command": "iverilog",
"type": "shell",
"args": [
"-t vvp",
"-o ${fileBasename}.vvp",
"-l /opt/Xilinx/14.7/ISE_DS/ISE/DCM_SP.v",
"-I /opt/Xilinx/14.7/ISE_DS/ISE/verilog/src/unisims",
"-I /opt/Xilinx/14.7/ISE_DS/ISE/verilog/src/XilinxCoreLib/",
"wslpath ${workspaceFolder}${pathSeparator}${relativeFileDirname}${pathSeparator}${fileBasenameNoExtension}.v"
],
"problemMatcher": [
"$tsc"
],
"presentation": {
"reveal": "always"
},
"group": "build"
}
Clearly I'm here because it doesn't work so I'm here to throw myself at the feet of smarter people.
This is what it actually runs
> Executing task in folder xilinx_projects: iverilog '-t vvp' '-o pulse2.v.vvp' '-l /opt/Xilinx/14.7/ISE_DS/ISE/DCM_SP.v' '-I /opt/Xilinx/14.7/ISE_DS/ISE/verilog/src/unisims' '-I /opt/Xilinx/14.7/ISE_DS/ISE/verilog/src/XilinxCoreLib/' 'wslpath C:\demand\xilinx_projects\pulse2\pulse2.v
I've been to the following pages for help:
Single quotes not escaped in debug commands #91578
how-do-i-use-bash-on-ubuntu-on-windows-wsl-for-my-vs-code-terminal
Regression: WSL Shell Task command containing spaces fails
Paths separators in build config being escaped/stripped out prior to build command being run #35593
All double quotes removed from command in tasks.json in powershell #72039
Variable Reference
And of course: Integrate with External Tools via Tasks
I see other people struggling with it. I can't tell if that is current. These things find a way dead ending when someone finally gets it or the problem goes away from some other feature that I must not know about.
I'm sure the answer is somewhere in those links. I just can't find one that works for me. I've tried all kinds of variations of escape characters and none work for me.
You'll also see that the final argument is obscene compared to what someone that knows what they are doing would use. That same command works in "command":, but not as an arg.
I try to avoid asking questions but this is killing me. I fill very close to being able to use tasks to do more but I find the documentation incomplete and without examples of what the shell sees.
You can probably see what I'm trying to accomplish. Can you offer any advice on how to do this as painlessly as possible?
From the "containing spaces fails" issue that you linked to, I wasn't able to get the original version of the sample "My Task" to work, so it almost does seem like the fixed regression has regressed again. Either that, or the new 2.0.0 task system doesn't parse it the same way.
That example used one long "command", but specified the "executable" as wsl.exe. Something else may have changed here, because reading the ${env:windir} as specified there doesn't work for me either when launching vscode from WSL. But no matter, I'm just going to leave off the path for now.
One alternative presented there was to specify each element as a separate arg (i.e. "args": [ "ls", "/", "&&", "echo", "OK", "#", "comment" ]). That does work for me, and your iverilog arguments seem to work when parsed that way as well. At least, it comes out as an unquoted command line. To be honest, the way the "Quoting" section of the Tasks doc reads, it sounds like that is the expected way to do it -- Have each element be a separate "arg". From that page:
If a command and arguments are provided, the task system will use single quotes if the command or arguments contain spaces.
That's exactly what we are seeing, of course.
But there's another alternative I found, as well. A comment further down that thread mentioned passing -c to the (old) ubuntu1804.exe executable. That led me to try something similar for the wsl.exe command, and it worked to pass in args of "-e", "sh", and "-c", along with the full commandline in the "command", like so:
{
// See https://go.microsoft.com/fwlink/?LinkId=733558
// for the documentation about the tasks.json format
"version": "2.0.0",
"tasks": [
{
"label": "Verilog: Compile iVerilog File",
"options": {
"shell": {
"executable": "wsl.exe",
"args": [
"-e"
"sh",
"-c"
]
}
},
"type": "shell",
"command": "iverilog -t vvp -o ${fileBasename}.vvp -l /opt/Xilinx/14.7/ISE_DS/ISE/DCM_SP.v -I /opt/Xilinx/14.7/ISE_DS/ISE/verilog/src/unisims -I /opt/Xilinx/14.7/ISE_DS/ISE/verilog/src/XilinxCoreLib/ wslpath ${workspaceFolder}${pathSeparator}${relativeFileDirname}${pathSeparator}${fileBasenameNoExtension}.v",
"problemMatcher": [
"$tsc"
],
"presentation": {
"reveal": "always"
},
"group": "build"
},
{
"label": "My Task",
"options": {
"shell": {
"executable": "wsl.exe",
"args": [
"-e",
"sh",
"-c"
]
}
},
"type": "shell",
"command": "ls / && echo OK # comment",
"problemMatcher": [],
"presentation": {
"reveal": "always"
},
"group": "build"
}
]
}
I believe that's your consolidated full command-line for iverilog. I've also included the "My Task" example, which is generic enough that it should work on any WSL system.
Can you replace corresponding setion of tasks.json with this ?
"type": "shell",
"command": "wsl",
"args": ["bash", "-c", "iverilog\
-t vvp -o ${fileBasename}.vvp -l /opt/Xilinx/14.7/ISE_DS/ISE/DCM_SP.v\
-I /opt/Xilinx/14.7/ISE_DS/ISE/verilog/src/unisims\
-I /opt/Xilinx/14.7/ISE_DS/ISE/verilog/src/XilinxCoreLib/\
$(wslpath '${workspaceFolder}${pathSeparator}${relativeFileDirname}${pathSeparator}${fileBasenameNoExtension}.v')"]

Variable names in vscode debugger are reduced to one letter instead of full variable names

I created a configuration in launch.json.
When I run using this configuration the variable names in my code are not used as variable names in the vscode debugging console.
Instead all variable names are reduced to one letter. For example a variable defined as const name in the code will show as the letter e in the vscode debugging console.
This also causes that I am unable to hover variables in the code to look for their value.
How come the variable names are reduced to one letter in the vscode debugging console?
Here is the launch config I use. Here it's used to run serverless functions locally. Though I suspect the issue is not related to that.
If necessary I can provide more info.
{
"type": "node",
"request": "launch",
"name": "Run one Serverless function",
"program": "${workspaceFolder}/node_modules/.bin/sls",
"args": [
"invoke",
"local",
"--function",
"nameOfTheFunction",
"--path",
"./myEvent.json"
],
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"env": { "AWS_PROFILE": "myProfile", "SLS_DEBUG": "*" }
}

Where is stdout for VS Code?

I am running Node.js in VS Code. I see output of console.log in the Debug Window.
Where does process.stdout.write go to? I can't find it in the Debug Console or any of the Output windows.
My launch.json is simply this:
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch Program",
"program": "${workspaceFolder}/job.js"
}
]
}
Looking at issues with process.stdout.write the suggested fixes are adding these to your launch config:
"console": "internalConsole",
"outputCapture": "std",
Especially the outputCapture entry is important.
Make sure the Debug Console is visible:
Ctrl + Shift + Y
Can you try to add "console": "internalConsole" to your config and see if it works?
As per the docs these are the available options for the console:
console - what kind of console to use, for example, internalConsole,
integratedTerminal, externalTerminal