2011-04-07 63 views
0

我編碼了我對netstat的解釋。但是如果狀態消息太長,我還是會遇到一些與製表符號相關的問題 。有沒有辦法來解決這個問題?兩個標籤不會解決這個問題。控制檯輸出的標籤問題

[*] nstat v.01 - maps port to process 
[*] by bubblegun 

Pid Port Proto Status Process 

4140  80 TCP LISTEN httpd.exe 
916  135 TCP LISTEN svchost.exe 
624  1028 TCP LISTEN lsass.exe 
3604  1031 TCP ESTABLISHED TeamViewer_Service.exe 
3604  1032 TCP ESTABLISHED TeamViewer_Service.exe 
+0

你能更準確地瞭解製表問題嗎? 它是「已建立」的線? – Aif 2011-04-07 18:28:45

+0

確切的說,它的最後兩行 – Bubblegun 2011-04-07 18:30:34

+2

你使用過printf格式的長度嗎? 'printf(「%20s」,mystring);' – Aif 2011-04-07 18:31:29

回答

1

嘗試printf中的width選項。例如:

printf("%8s%8s%8s%12s %s\n", "Pid","Port","Proto","Status","Process"); 
printf("%8d%8d%8s%12s %s\n", 10, 200, "TCP", "LISTEN", "httpd.exe"); 
printf("%8d%8d%8s%12s %s\n", 101, 20100, "TCP", "ESTABLISHED", "svchost.exe");