launch.json args字段中的Visual Studio Community 2017空间 [英] Visual Studio Community 2017 spaces in launch.json args field

查看:122
本文介绍了launch.json args字段中的Visual Studio Community 2017空间的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在尝试为Visual Studio Community 2017中基于CMake的项目设置调试启动参数.通常,这可以通过launch.vs.json文件完成.但是,我需要传递的参数中包含空格.例如,下面的launch.vs.json文件应将争辩参数FIRST ARGUMENT和SECOND ARGUMENT作为第一个和第二个参数传递.但是,该程序最终得到4个参数:FIRST,ARGUMENT,SECOND和ARGUMENT.我已经尝试了各种不同的空格编码,但是无法在结果参数中获得正确编码的空格.这特别成问题,因为我程序的参数之一是C:\ Program Files内的路径.因此,该路径分为2个独立的参数,而不是应有的参数.如何使Visual Studio在参数中允许空格?

I'm currently trying to set the debugging startup arguments for a CMake based project in Visual Studio Community 2017. Normally this would be done via the launch.vs.json file. However, the arguments that I need to pass contain spaces in them. For example, the below launch.vs.json file should pass the arguemnts FIRST ARGUMENT and SECOND ARGUMENT as the first and second argument. However, the program ends up getting 4 arguments: FIRST, ARGUMENT, SECOND, and ARGUMENT. I've tried various different encodings for spaces, but cannot get a space to be encoded properly in the resulting arguments. This is especially problematic as one of the arguments to my program is a path inside C:\Program Files. As such, the path is broken into 2 separate arguments, rather than one as it should be. How do I make Visual Studio allow spaces within an argument?

作为参考,使用此命令通过命令行启动可以正常工作:

For reference, launching via the command line with this command works as expected:

argtest.exe "FIRST ARGUMENT" "SECOND ARGUMENT"

launch.vs.json

launch.vs.json

{
  "version": "0.2.1",
  "defaults": {},
  "configurations": [
    {
      "type": "default",
      "project": "CMakeLists.txt",
      "projectTarget": "argtest.exe",
      "name": "argtest.exe",
      "args": ["FIRST ARGUMENT", "SECOND ARGUMENT"]
    }
  ]
}

test.c

#include <stdio.h>
int main(int argc, char ** argv) {
    int i;
    for (i = 0; i < argc; i++)
        printf("%d = %s\n", i, argv[i]);
    return 0;
}

CMakeLists.txt

CMakeLists.txt

cmake_minimum_required (VERSION 2.8.8)
project (argtest)
SET( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_SOURCE_DIR}/ )
add_executable(argtest test.c)

推荐答案

您需要将引号包含在args字符串中并对其进行转义.例如:

You need to include the quotes in the args strings and escape them. For example:

{
  "version": "0.2.1",
  "defaults": {},
  "configurations": [
    {
      "type": "default",
      "project": "CMakeLists.txt",
      "projectTarget": "argtest.exe",
      "name": "argtest.exe",
      "args": ["\"FIRST ARGUMENT\"", "\"SECOND ARGUMENT\""]
    }
  ]
}

这篇关于launch.json args字段中的Visual Studio Community 2017空间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆