How do I replace the backslashes with forward slashes in the Visual Studio Code build task argument.
I've tried using backslashes in my Bash command, but the console simply removes the slashes.
"command": "xxxxxxxx.exe",
"type": "shell",
"args": [
"--dir=${workspaceFolder}",
]
In the console it appears to be:
> Executing task: xxxxxxxx.exe --dir=C:UsersUserDesktopProject
But I want it to be:
> Executing task: xxxxxxxx.exe --dir=C:/Users/User/Desktop/Project/
Something using bash built-in ${variable//string/substitution}:
"command": "xxxxxxxx.exe",
"type": "shell",
"args": [
"--dir=${workspaceFolder//\\/\/}",
]
As for me, just switch default shell to cmd done the job. I installed git-bash as my default shell within vscode. When I tried to debug ts file, the shell complained something like your case, the path is a string without any slash or backslash.
This is my launch.json.
{
{
"type": "node",
"request": "launch",
"name": "Debug Current",
"preLaunchTask": "tsc: build - tsconfig.json",
"skipFiles": ["<node_internals>/**"],
"program": "${file}",
"outFiles": ["${workspaceFolder}/dist/*.js"]
}
]
}
Did you double the backslashes? They are a quoting character, so you likely have to use one to quote the next.
$: echo "C:\Users\Public" | sed 's,\\,/,g'
C:/Users/Public
Using parameter expension without spawning a sed -
$: x="C:\Users\Public"
$: echo "${x//\\/\/}"
C:/Users/Public
Related
I am trying to run my pod using below command but keep getting error:
error: Invalid JSON Patch
kubectl run -i tmp-pod --rm -n=my-scripts --image=placeholder --restart=Never --overrides= "$(cat pod.json)"
Here is my pod.json file:
{
"apiVersion": "v1",
"kind": "Pod",
"metadata": {
"name": "test",
"namespace": "my-ns",
"labels": {
"app": "test"
}
},
"spec": {
"containers": [
{
"name": "test",
"image": "myimage",
"command": [
"python",
"/usr/bin/cma/excute.py"
]
}
]
}
}
What am I doing wrong here?
I did a bit of testing and it seems there is an issue with Cmder not executing $() properly - either not working at all, or treating newlines as Enter, and thus executing a commant before entire JSON is passed.
You may want to try running your commands in PowerShell:
kubectl run -i tmp-pod --rm -n=my-scripts --image=placeholder --restart=Never --overrides=$(Get-Content pod.json -Raw)
There is a similar issue on GitHub [Windows] kubectl run not accepting valid JSON as --override on Windows (same JSON works on Mac) #519. Unfortunately, there is no clear solution for this.
Possible solutions are:
Passing JSON as a string directly
kubectl run -i tmp-pod --rm -n=my-scripts --image=placeholder --restart=Never --overrides='{"apiVersion":"v1","kind":"Pod","metadata":{...}}'
Using ' instead of " around overrides.
Using triple quotes """ instead of single quotes " in JSON file.
I am trying to map a custom shortcut to VS code that will paste the following string (which clears the console), using the multi_command tool:
"command": "multiCommand.clearConsole",
"sequence": [
{
"command": "type",
"args": {
"text": "print("\\033\[2J)
}
}
]
I have used a double backslash to escape the first backslash, but I need a way of escaping the '[' open bracket.
Does anyone know if it's possible? or an easier way to do it? I just want to clear the console which is hosted on an external device (interacting via PyCOM Console) and interacts via python command line.
Cheers!
You need to escape the double-quote and the backslash before [, the bracket is a valid JSON character:
{
"command": "multiCommand.clearConsole",
"sequence": [{
"command": "type",
"args": {
"text": "print(\"\\033\\[2J)"
}
}]
}
This keybinding - chose whatever keybinding you want - will clear the console:
{
"key": "ctrl+shift+z",
"command": "workbench.action.terminal.sendSequence",
"args": { "text": "clear\u000d" }
}
or you could use that "text" in your macro.
Focus in editor.
I have configured my task.json and c_cpp_properties.json so that I may compile my main.cpp program. In order to proceed, I must press
Ctrl + Shift + B
As soon as I do a terminal pops up and alters me of an error:
Executing task in folder C++: C:\MinGW\bin\g++.exe -g main.cpp -o c:\Users\Me\Desktop\C++\.vscode\tasks.exe <
/bin/bash: C:MinGWbing++.exe: command not found
The terminal process terminated with exit code: 127
Terminal will be reused by tasks, press any key to close it.
I don't why this is happening since I've already checked that MinGW is installed in my computer with the correct PATH. To ensure that I do I typed the following in the terminal:
g++ --version
g++ (MinGW.org GCC-8.2.0-3) 8.2.0
Copyright (C) 2018 Free Software Foundation, Inc.
I also checked the path according to this figure
The only closest problem related to mine is in this Github link. I've also already tried changing the file directory shown in the code below using this thread but I still encounter this error.
Here are my JSON files which are inside my .vscode file:
tasks.json:
{
"version": "2.0.0",
"tasks": [
{
"label": "echo",
"type": "shell",
"command": "C:\\MinGW\\bin\\g++.exe",
"args": [
"-g",
"main.cpp",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"group": {
"kind": "build",
"isDefault": true
},
"problemMatcher": []
}
]
}
c_cpp_properties.json:
{
"configurations": [
{
"name": "Win32",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [
"_DEBUG",
"UNICODE",
"_UNICODE"
],
"windowsSdkVersion": "10.0.17134.0",
"compilerPath": "C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.14.26428/bin/Hostx64/x64/cl.exe",
"cStandard": "c11",
"cppStandard": "c++17",
"intelliSenseMode": "msvc-x64",
"browse": {
"path": [
"${workspaceRoot}",
"C:\\MinGW\\lib\\gcc\\mingw32\\8.2.0\\include\\c++"
],
"limitSymbolsToIncludedHeaders": true,
"databaseFilename": ""
}
}
],
"version": 4
}
I should expect to see a ".exe" after compiling but I can't due to the error.
After spending two days messing around with this I've finally able to correct setup C++ on VS Code and resolved the error.
According to the png image from above, I've included "C:\MinGW\bin" within the user variable "Path" under the dialogue box "User variables for Me". After a simple restart on my computer, I was able to build my project (Shift + Ctrl + B) with no problems.
I'm having trouble getting anaconda prompt to work with VSCode shell launcher.
Im trying to set up the Shell Launcher Extension for VSCode to run the following terminals on windows 10:
Git Bash,
CMD,
Powershell,
Anaconda Prompt
I have configured my settings. json with the following code:
{
"terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe",
"shellLauncher.shells.windows": [
{
"shell": "C:\\Program Files\\Git\\bin\\bash.exe",
"args": [],
"label": "bash"
},
{
"shell": "cmd",
"args": [],
"label": "cmd"
},
{
"shell": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
"args": [],
"label": "PowerShell"
},
{
"shell": "cmd",
"args": [
"/K",
"C:\\ProgramData\\Anaconda3\\Scripts\\activate.bat C:\\ProgramData\\Anaconda3"
],
"label": "Conda"
}
]
}
As you can see Bash is my default terminal that opens with ctrl+` and my shell launcher opens with ctrl+shift+t .
The Shell launcher lists my all of the entries above, and all terminals launch through Shell Launcher except Anaconda Prompt.
From what I understand according to this blog post: How to Add Anaconda Prompt to VSCode Integrated Terminal,
Anaconda Prompt extends windows cmd and I just need to pass in the Arguments that run the script.
I pulled the args out of the properties of Anaconda menu, but when I try to launch the anaconda prompt I get the following error message:
The terminal process command 'cmd /K 'C:\ProgramData\Anaconda3\Scripts\activate.bat C:\ProgramData\Anaconda3'' failed to launch (exit code: 2)
Here is the path from the properties menu of the anaconda prompt desktop icon that works normally.
%windir%\System32\cmd.exe "/K" C:\ProgramData\Anaconda3\Scripts\activate.bat C:\ProgramData\Anaconda3
I have tried adding the actual path of cmd as:
%windir%\\System32\\cmd.exe
, but this just removes the Anaconda prompt from the Shell Launcher drop-down menu completely.
How can I fix this?
Any help will be appreciated. :)
I fixed it. "cmd.exe" was the path that worked.
For anyone else who want's to set up multiple integrated terminals in VScode for windows 10 here's the settings for the Shell Launcher extension that I am using.
This sets the my default terminal to Git Bash and allows me to open bash, cmd, Anaconda prompt and powershell with Shell Launcher.
"terminal.integrated.shell.windows": "C:\\Program Files\\Git\\bin\\bash.exe",
"shellLauncher.shells.windows": [
{
"shell": "C:\\Program Files\\Git\\bin\\bash.exe",
"args": [],
"label": "bash"
},
{
"shell": "cmd.exe",
"args": [],
"label": "cmd"
},
{
"shell": "cmd.exe",
"args": [
"/K",
"C:\\ProgramData\\Anaconda3\\Scripts\\activate C:\\ProgramData\\Anaconda3"
],
"label": "Conda"
},
{
"shell": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe",
"args": [],
"label": "PowerShell"
}
]
Happy Hacking. ;)
I am struggling to pass input parameter to packer provisioning script. I have tried various options but no joy.
Objective is my provision.sh should accept input parameter which I send during packer build.
packer build -var role=abc test.json
I am able to get the user variable in json file however I am unable to pass it provision script. I have to make a decision based on the input parameter.
I tried something like
"provisioners":
{
"type": "shell",
"scripts": [
"provision.sh {{user `role`}}"
]
}
But packer validation itself is failed with no such file/directory error message.
It would be real help if someone can help me on this.
Thanks in advance.
You should use the environment_vars option, see the docs Shell Provisioner - environment_vars.
Example:
"provisioners": [
{
"type": "shell"
"environment_vars": [
"HOSTNAME={{user `vm_name`}}",
"FOO=bar"
],
"scripts": [
"provision.sh"
],
}
]
If your script is already configured to use arguments; you simply need to run it as inline rather than in the scripts array.
In order to do this, the script must exist on the system already - you can accomplish this by copying it to the system with the file provisioner.
"provisioners": [
{
"type": "file",
"source": "scripts/provision.sh",
"destination": "/tmp/provision.sh"
},
{
"type": "shell",
"inline": [
"chmod u+x /tmp/provision.sh",
"/tmp/provision.sh {{user `vm_name`}}"]
}
]