Vs code passes parameters containing semicolons to the program
Closed this issue · 6 comments
int main(int argc, char *argv[]) {
for (int i = 0; i < argc; i++)
{
printf("%s\n", argv[i]);
}
return 0;
}
set args:["1;3"]
i hope display
a.out
1;3
but result is
a.out
1
my system is ubuntu 16.04
It is very unlikely that VSCode has anything to do with that.
Ho do you run the program?
I need to input arguments that is a string with semicolons, like"address;topic".
When the arguments comes from ubuntu terminal command, the argument is "address;topic" exactly what I want.
But when they are comes from launch.json which is needed in vscode, all the characters behind the semicolon is ignored. It becomes to "address" without ";topic".
How to set the "args" parameter in launch.json to get strings input with semicolons?
@aeschli
Having one "args": [ "address;topic"]
is IMO the right thing to do.
Can you paste the full configuration that you have in launch.json
? I'd like to see the type of the configuration.
Hi!@aeschli
Thanks for your reply.
Bellow is my semicolons_test.c
#include <stdio.h>
int main(int argc, char *argv[])
{
for (int i=0;i<argc;i++)
{
printf("%s\n",argv[i]);
}
return 0;
}
And launch.json
"version": "0.2.0",
"configurations": [
{
"name": "(gdb) Launch",
"type": "cppdbg",
"request": "launch",
"program": "${workspaceFolder}/semicolons-test",
"args": ["address;topic"],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "M"
}
]
output in Vscode
/home/dreamdeck/Desktop/test/semicolons-test
address
input and output in Linux terminal
$ gcc -o semicolons-test semicolons_test.c
$ ./semicolons-test "address;topic"
./semicolons-test
address;topic
We are now properly escaping ';' for unix shells.