0

I am trying to build a custom sublime-build that executes c++ programs in powershell. I want powershell to exit itself on pressing enter or any other key. How can this be done ?

This is my sublime-build so far..


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

This is how it looks.. enter image description here

Thanks

Shashank KR
  • 83
  • 1
  • 9
  • Off-topic, but good to read anyway: https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice and https://stackoverflow.com/questions/31816095/why-should-i-not-include-bits-stdc-h – MattDMo Aug 07 '22 at 03:01

1 Answers1

0

Give this a shot.

PSHostRawUserInterface.ReadKey Method https://learn.microsoft.com/en-us/dotnet/api/system.management.automation.host.pshostrawuserinterface.readkey?view=powershellsdk-7.0.0

 {
    "cmd": ["g++", "${file}", "-o", "${file_base_name}.exe"],
    "file_regex": "^(..[^:]*):([0-9]+):?([0-9]+)?:? (.*)$",
    "working_dir": "${file_path}",
    "selector": "source.c, source.c++",
    "cmd": ["start", "powershell", "-NoExit","& '${file_path}/${file_base_name}.exe';$Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');Exit"],
    "shell": true,
    "variants":
    [
        {
            "name": "Run",
            "cmd": ["start", "powershell", "-NoExit","& ${file_path}/${file_base_name}.exe;$Host.UI.RawUI.ReadKey('NoEcho,IncludeKeyDown');Exit"],
            "shell": true
        }
    ]
}
postanote
  • 15,138
  • 2
  • 14
  • 25