How to add double quotes in sublime build file?

时间:2017-06-19 14:00:35

标签: c++ cmd g++ sublimetext2 sublimetext3

I want to compile my C++ program in sublime text 3 and run it in cmd. For that, I created a new build system(Tools-->Build System).

{
"cmd": ["g++", "${file}", "-o", "${file_path}/${file_base_name}"],
"file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
"working_dir": "${file_path}",
"selector": "source.c, source.c++",
"shell": "true",
"variants":
[
    {
        "name": "Run",
        "cmd": ["g++", "${file}", "-o", "${file_path}/${file_base_name}" ,"&&","start", "cmd", "/k", "$file_base_name"],
        "shell": true
    }
] }

This executes:

g++ file_location -o file_location && start cmd /k file_location

What I want to implement is(so that it holds the screen after execution finishes, and should exit on pressing any key in cmd):

g++ file_location -o file_location && start cmd /c "file_location && pause>nul"

(i.e replace k with c and implement double quotes)

I have tried \"

Instead of passing " , it passes whole \" which produces error in cmd.

What should i do?

1 个答案:

答案 0 :(得分:1)

好吧,我自己想通了。 我应该删除[],以便传递单个字符串而不是数组。现在,要使用双引号,请写\"而不是"

原文:"cmd": ["g++", "${file}", "-o", "${file_path}/${file_base_name}" ,"&&","start", "cmd", "/k", "$file_base_name"]

修改"cmd": "g++ ${file} -o ${file_path}/${file_base_name} && start cmd /c /"$file_base_name &&pause/" "