IT漫步

技术生活札记©Yaohui




Two ways to retrieve process id while startup a process via Windows command line

一个特殊的机缘, 需要通过cmd.exe启动一个进程, 并且获取该启动后进程的Process ID, 搜罗到两种方法: 1. 通过wmic process call create wmic如果创建进程成功,将返回一个ReturnValue为0类JSON结构的输出, 从中获取ProcessId: C:\app>cmd.exe /C wmic process call create "c:\app\cluster\GatewayServer.exe start -id 6", "c:\app" Executing (Win32_Process)->Create() Method execution successful. Out Parameters: instance of __PARAMETERS { ProcessId = 19420; ReturnValue = 0; }; wmic如果创建进程失败, 将返回一个ReturnValue非0的输出: C:\app>wmic process call create "cluster\GatewayServer.exe start -id 6", "c:\app" Executing (Win32_Process)->Create() Method …


Close TCP and UDP ports via windows command line

The CurrPorts tool from Nirsoft can easily close a TCP/UDP connection without kill the Process via Windows command line cports.exe /close <Local Address> <Local Port> <Remote Address> <Remote Port> Example: cports.exe /close 172.24.3.102 51512 172.25.1.206 8007 Download: CurrPorts Refer: https://superuser.com/questions/384758/how-to-kill-a-particular-tcp-connection-in-windows/384761#384761


DOS中通过chcp修改console code page

UTF-8格式的日志文件, DOS中通过type命令查看时显示乱码: C:\app\Manager\Log\RootManagerServer>type Root_20200527_135730_Trace.html 1590559051 0 0 Trace 0 0 Bind Port:Listen:8800<br> 1590559051 0 0 Trace 0 0 鏈嶅姟鍣ㄧ洃鍚鍙?8800<br> 1590559051 0 0 Trace 0 0 Bind Port:Listen:9800<br> 1590559051 0 0 Trace 0 0 瀹㈡埛绔洃鍚鍙?9800<br> 通过chcp命令修改code page为65001后显示正常: C:\app\Manager\Log\RootManagerServer>type Root_20200527_135730_Trace.html 1590559051 0 0 Trace 0 0 Bind Port:Listen:8800<br> 1590559051 0 0 Trace 0 0 服务器监听端口:8800<br> 1590559051 0 …

Proudly powered by WordPress