【发布时间】:2020-07-08 19:04:54
【问题描述】:
我正在使用 Powershell 编写一个简单的 TCP/IP 服务器。我注意到 Ctrl-C 不能中断 AcceptTcpClient() 调用。 Ctrl-C 在通话后工作正常。搜了一圈,目前没有人报告过类似的问题。
下面的简单代码可以重复这个问题。我正在使用带有本机 Powershell 终端的 Windows 10 最新补丁,而不是 Powershell ISE。
$listener=new-object System.Net.Sockets.TcpListener([system.net.ipaddress]::any, 4444)
$listener.start()
write-host "listener started at port 4444"
$tcpConnection = $listener.AcceptTcpClient()
write-host "accepted a client"
这就是我运行它时发生的情况
ps1> .\test_ctrl_c.ps1
listener started at port 4444
(Ctrl-C doesn't work here)
【问题讨论】:
标签: powershell tcp client control-c