how to pass multiple args to vscode task command? - visual-studio-code

in tasks.json I am using the "args" property to specify the arguments to pass to "command":"gulp". But when I run the task in vscode, only the first argument is being passed to gulp.
I want to run a gulp task against a single file. In gulpfile.js I am using the process.argv array to retrieve the command line arguments. So, on the command line I enter "gulp copy3 --file abc.js" and the copy3 task is run. The code then reads the argv array to get the name of the file being copied.
this code works from the command line. But does not work when I run it as a task in vscode. How to do that?
the gulpfile.js code:
gulp.task('copy3', function( )
{
console.log(process.argv) ;
let pattern = '*.js' ;
// single file to copy
if (( process.argv.length >= 5 ) && ( process.argv[3] == '--file' ))
{
let fileName = process.argv[4] ;
pattern = fileName ;
}
console.log('pattern:' + pattern ) ;
return gulp.src(pattern).pipe(gulp.dest('dev'));
}) ;
the tasks.json file
{
"version": "2.0.0",
"tasks": [
{
"taskName": "copy3",
"command": "gulp",
"args": [ "copy3", "--file", "${fileBasename}" ],
"problemMatcher": []
}
]
}
Here is the terminal output:
[10:52:57] Using gulpfile C:\vscTest\rpgproj\gulpfile.js
[10:52:57] Starting 'copy3'...
[ 'C:\\Program Files\\nodejs\\node.exe',
'C:\\vscTest\\rpgproj\\node_modules\\gulp\\bin\\gulp.js',
'copy3' ]
pattern:*.js
[10:52:57] Finished 'copy3' after 16 ms
thanks,

I made a couple of small changes, try:
{
"label": "Tasks: copy3",
"type": "shell",
"command": "gulp",
"args": [ "copy3", "--file", "${fileBasename}" ],
"problemMatcher": []
}
and your entire code works perfectly. Make sure to reload vscode after modifying the tasks.json.

VSCode appears to have a built-in gulp extension. This seems to scan your gulpfile for tasks and list them for you. It also seems to ignore the args option.
The workaround is to use the full path to gulp as the command e.g. ./node_modules/.bin/gulp to bypass it.

Related

How to fix: "The asset path must start with the project source root"?

We have an nrwl/nx project, that we can build on Windows, but it fails on Linux (Ci sytem).
The error is:
The /root/dev/apps/dmc-svr/src/assets asset path must start with the project source root: apps\dmc-svr\src
It seems to be a Windows/Linux path issue
The problem was a Windows like path for the sourceRoot property in project.json
{
"sourceRoot": "apps\\dmc-svr\\src",
"targets": {
"build": {
"executor": "#nrwl/node:build",
"options": {
"assets": [
"apps/dmc-svr/src/assets",
]
}
}
}
}
the fix is to simply replace the backslash \\ with a slash \: sourceRoot": "apps/dmc-svr/src"
We guess that this has been generated by some nx-schema.

Change default terminal in VS Code to cmd

When I open VS Code, the default terminal is PowerShell and the default path is PS E:\Research\GM\Articles\Modularity\Covariance network\Graph theory\Metric basics\Consensus clustering\clustering_programs_5_2.
Q1: How could I change the default path in PowerShell to C:\Users<UserName>? (red line below)
Q2: How could I change the default terminal from PowerShell to cmd? (yellow circle below)
#############################################################################
I followed Geeky's method which worked well. However, the default path is still E:\Research\GM\Articles\Modularity\Covariance network\Graph theory\Metric basics\Consensus clustering\clustering_programs_5_2 rather than something like C:\Users<UserName>:
Press Ctrl + Shift + P. Type "def" and the default terminal selection option pops.
Click on it and select your preferred terminal
Alternatively, add this in your settings.json file
"terminal.integrated.defaultProfile.windows": "Command Prompt",
If the following code exists already in your settings.json file or else add the following code also
"terminal.integrated.profiles.windows": {
"PowerShell": {
"source": "PowerShell",
"icon": "terminal-powershell",
"path": "C:\\windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"
},
"Command Prompt": {
"path": ["${env:windir}\\Sysnative\\cmd.exe", "${env:windir}\\System32\\cmd.exe"],
"args": [],
"icon": "terminal-cmd"
},
}

How to run path setting script in vscode terminal at startup?

I have a script which sets path variables. I have to run this script manually every time I start a new terminal instance.
I am looking for an automated way to run this script at startup for every terminal instance.
I have tried the below approach which doesn't work
{
"terminal.integrated.profiles.windows": {
"Command Prompt": {
"path": "cmd.exe",
"args": [
"-noexit",
"-file",
"h:\\all-languages-env.cmd"
]
}
},
"terminal.integrated.defaultProfile.windows": "Command Prompt",
}
I am expecting the script h:\all-languages-env.cmd to run at every terminal(Command Prompt) startup.
The script file is as below
#ECHO OFF
call devtools isSupported nodejs 16.13.0 || exit /B %ERRORLEVEL%
call devtools isSupported phantomjs 2.1.1 || exit /B %ERRORLEVEL%
set npm_config_registry=http://example.com
set npm_config_user_agent="npm/{npm-version} node/{node-version} {platform} {arch} | NDS %USERNAME% %COMPUTERNAME%"
set SASS_BINARY_SITE=http://example.com/node-sass
set SPAWN_WRAP_SHIM_ROOT=H:\.nodejs
set CHROME_BIN="C:\Program Files (x86)\Google\Chrome\Application\chrome.exe"
set npm_config_prefix=H:\.nodejs\npm\8
set npm_config_cache=H:\.nodejs\npm\8\cache
set npm_config_tmp=H:\.nodejs\npm\8\tmp
set NODEJS_16_13_0=H:\nodejs\16
set PATH=%NODEJS_16_13_0%;H:\.nodejs\npm\8;%PATH%
type nul > H:\nodejs\16\lastUsed
set PHANTOMJS_2_1_1=H:\phantomjs\2\bin
set PHANTOMJS_BIN=%PHANTOMJS_2_1_1%\phantomjs.exe
set PATH=%PHANTOMJS_2_1_1%;%PATH%
type nul > H:\phantomjs\2\lastUsed
ECHO javascript environment set
cmd.exe uses different arguments
{
"terminal.integrated.profiles.windows": {
"Command Prompt": {
"path": "cmd.exe",
"args": [
"/K",
"h:\\all-languages-env.cmd"
]
}
},
"terminal.integrated.defaultProfile.windows": "Command Prompt",
}

Unable to use environment variables in VS Code launch configuration

I have the following in my workspace settings.json file:
"terminal.integrated.env.osx": {
"AUTH_TOKEN": "secret_XXXXXX"
}
However, when trying to pass this via a launch command (defined in launch.json):
{
"name": "Example: Query",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/examples/query.py",
"args": [ "${env:AUTH_TOKEN}" ]
}
The resulting command contains an empty string for the argument:
/usr/bin/env /.../.venv/bin/python /.../debugpy/launcher 58644 -- /.../examples/query.py ""
However, if I print the variable from within the script, it is set properly.
I believe there is an ordering issue, such that the launch.json commands are generated before the terminal environment is set up - resulting in empty vars. Any ideas how to propagate the env value to the command line?
Update: I have also tried using a .env file for the variables (rather than settings.json), but the result is the same.
Try using "env" in launch.json...
{
"name": "Example: Query",
"type": "python",
"request": "launch",
"program": "${workspaceFolder}/examples/query.py",
"args": ["${AUTH_TOKEN}"], // using var from env on args
"env": {
"AUTH_TOKEN": "XXXX",
"ENV2" : "XXX"
}
}
you can use envs from file too
{
// ...
"args": ["${AUTH_TOKEN}"],
"envFile": "${workspaceFolder}/local.env",
}
You can create a .env file, and then put the variable in there, and read it from the environmental variables in the program instead of it being an argument.

Ncurses.h ( (.text+0xd): undefined reference to `initscr') visual code Ubuntu

I need to know why VS code is not compiling ncurses.h. but it is possible to compile in the terminal ubuntu. this message is appearing on the VS code. (.text+0xd): undefined reference to `initscr'
the code runner extension configuration add -lncurses before -o
"code-runner.executorMap": {
"c": "cd $dir && gcc $fileName -lncurses -o $fileNameWithoutExt && $dir$fileNameWithoutExt "
}
I solved this problem adding "-lncurses" in the "args" (tasks.json)
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}/${fileBasenameNoExtension}",
"-lncurses" <--------- add the library ("-lncurses" ) here
],