[英]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.