简体   繁体   English

程序执行后,如何在按键上退出 PowerShell?

[英]How to exit PowerShell on a keypress, after the program has been executed?

I am trying to build a custom sublime-build that executes c++ programs in powershell.我正在尝试构建一个自定义的 sublime-build 来执行 powershell 中的 c++ 程序。 I want powershell to exit itself on pressing enter or any other key.我希望 powershell 在按 enter 或任何其他键时自行退出。 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..看起来是这样的。。 在此处输入图像描述

Thanks谢谢

Give this a shot.试一试。

PSHostRawUserInterface.ReadKey Method https://docs.microsoft.com/en-us/dotnet/api/system.management.automation.host.pshostrawuserinterface.readkey?view=powershellsdk-7.0.0 PSHostRawUserInterface.ReadKey 方法https://docs.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
        }
    ]
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 执行脚本后始终会清除 PowerShell 窗口 - The PowerShell window is always cleaned after a script has been executed 如何检查当前登录会话中是否已执行程序? (视窗) - How do I check if a program has already been executed during the current login session? (Windows) Python和终端:文件执行后保持python环境 - Python and terminal: keep python environment after the file has been executed 修改旧的Windows程序,在没有源访问权的情况下按键后不调用exit - Modifying an old Windows program not to call exit after a keypress without source access 从批处理文件启动的程序终止后,如何保持控制台窗口打开? - How to keep console window open even after program started from batch-file has been terminated? C ++-如何退出没有窗口的程序? - C++ - How can I exit a program that has no window? 检查VirtualFreeEx是否已完成/执行 - Check if VirtualFreeEx has been completed/executed Java:如何检查程序是否已正确启动? - Java: how to check if a program has been correctly launched? 什么是找到程序运行后更改磁盘上哪些文件的好工具/方法? - What's a good tool/method to find which files on disk have been changed after a program has been run? 使用 Windows 任务计划程序启动程序后如何最小化程序? - How to start a program minimised when the program has been started using Windows Task Scheduler?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM