简体   繁体   中英

Auto run .exe file after building c++ using sublime text 3

I found this build configuration online:

{
  "cmd": ["C:/Program Files (x86)/Dev-Cpp/MinGW64/bin/g++", "-o", "${file_path}/${file_base_name}.exe", "-static-libgcc", "-static-libstdc++", "${file_path}/${file_base_name}.cpp"],
  "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
  "selector": "source.cpp",
  "shell": true,
  "variants":[
        {
            "name": "Run",
            "cmd": ["start","cmd", "/K" , "$file_base_name"]
        }
    ],
}

Is there any way to AUTOMATICALLY run the.exe program after it gets built rather than separately using CTRL+B to build and CTRL+SHIFT+B to run?

I tried this:

{
  "cmd": ["C:/Program Files (x86)/Dev-Cpp/MinGW64/bin/g++", "-o", "${file_path}/${file_base_name}.exe", "-static-libgcc", "-static-libstdc++", "${file_path}/${file_base_name}.cpp"],
  "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
  "selector": "source.cpp",
  "shell": true,
  "cmd": ["start","cmd", "/K" , "$file_base_name"]
}

But it only displays the older.exe file rather than the newly built one.

The build systems for C and C++ that ship with Sublime out of the box do exactly that; their names are C Single File and C++ Single File (differing only in using g++ versus gcc ):

{
    "shell_cmd": "g++ \"${file}\" -o \"${file_path}/${file_base_name}\"",
    "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
    "working_dir": "${file_path}",
    "selector": "source.c++",

    "variants":
    [
        {
            "name": "Run",
            "shell_cmd": "g++ \"${file}\" -o \"${file_path}/${file_base_name}\" && \"${file_path}/${file_base_name}\""
        }
    ]
}

The main build compiles only, the variant compiles, then runs.

This requires that your compiler be properly set up and added to the PATH . Note also that it runs the build directly inside of Sublime; if you want it to execute in an external terminal window like that build does, you will need to modify the command that runs it accordingly.

If your program expects to gather input interactively from the user, you will need to either run the program externally or use the Terminus package to make the build interactive. The README has instructions as well as a link to a tutorial video that describes how to convert the build.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM