Using Python Library: prettytable beautify the output form of JPS command

Simply onlinezuozuo 2021-09-15 13:57:22
using python library prettytable beautify

Use Python library : PrettyTable beautify jps The output form of the command

1、 explain

jps The default display is not very friendly , Without port , So let's use this library to beautify the output

2、 Code

# -*- coding:utf-8 -*-
# For formatting jps Output 
import sys
from prettytable import PrettyTable
import os
def shell(cmd):
p = os.popen(cmd)
x =
return x
def last_index_of(s):
a = s.split('/')
return a[len(a) - 1]
def get_port(s):
port = shell('lsof -ni | grep ' + arg[0] + ' | grep LISTEN | awk \'{print $9}\'')
ar = port.split('\n')
for l in ar:
p = l.replace('*:', '')
if p.isdigit():
return p
return ''
# Header 
table = PrettyTable(['PID', 'Port', 'Jar Name', 'File Path'])
for line in shell('jps -l').split('\n'):
arg = line.split(' ')
if len(arg) == 1:
table.add_row([arg[0], get_port(arg[0]), '', ''])
if len(arg) == 2:
table.add_row([arg[0], get_port(arg[0]), last_index_of(arg[1]), arg[1]])
if __name__ == '__main__':

3、 function

 Insert picture description here

本文为[Simply onlinezuozuo]所创,转载请带上原文链接,感谢

  1. 从0起步学Python(附程序实例讲解)第1讲
  2. 从0起步学Python(附程序实例讲解)第1讲
  3. Apprendre Python à partir de 0 (avec des exemples de programme) leçon 1
  4. Apprendre Python à partir de 0 (avec des exemples de programme) leçon 1
  5. With Python, I'll take you to enjoy it for a month when the Mid Autumn Festival is coming
  6. You can't write interface software in Python! Which software on sale has no UI?
  7. Python国内外原题解析及源码1~15
  8. Python实现长篇英文自动纠错~
  9. Python implémente la correction automatique des erreurs en anglais long
  10. Analyse des problèmes originaux et code source de Python au pays et à l'étranger 1 ~ 15
  11. 一张思维导图学Python之表白
  12. Python教学中课程思政建设的研究探索2
  13. Recherche sur la construction idéologique et politique du Programme d'études dans l'enseignement Python 2
  14. Une présentation de la cartographie mentale Python
  15. Python高级用法总结(8)-函数式编程
  16. Python + Mirai development QQ robot starting tutorial (2021.9.9 test is valid)
  17. Python Advanced use Summary (8) - functional Programming
  18. How to get started with Python and share learning methods for free. All you want to know is here
  19. Python + Mirai development QQ robot starting tutorial (2021.9.9 test is valid)
  20. Python趣味编程中(PPT适合青少儿和零基础学习Python)
  21. Python基础第1讲(含代码、Python最新安装包、父与子的编程之旅:与小卡特一起学Python中文版)
  22. 用 Python 增强 Git
  23. Python基礎第1講(含代碼、Python最新安裝包、父與子的編程之旅:與小卡特一起學Python中文版)
  24. Base Python leçon 1 (y compris le Code, le dernier paquet d'installation Python, le voyage de programmation parent - enfant: apprendre la version chinoise de python avec le petit Carter)
  25. Dans la programmation amusante Python (ppt pour les jeunes enfants et l'apprentissage de base zéro Python)
  26. 非常好的题目详解Python字典的用法
  27. Python teaches you to build wechat push live Betta reminder from 0 (single room simplified version)
  28. Python 协程与 JavaScript 协程的对比
  29. 手把手带你用Python实现一个量化炒股策略
  30. Main dans la main pour mettre en œuvre une stratégie quantitative de spéculation boursière en python
  31. Comparaison des coproductions Python et JavaScript
  32. 【python种子项目ppc】一行代码生成项目与开发详细指导
  33. Docker 部署一个用 Python 编写的 Web 应用
  34. Python - poetry(4)管理环境
  35. Python - poetry(2)命令介绍
  36. [Python Seed Project PPC] a line of Code Generation Project and Development detailed guidance
  37. Introduction à la commande python - Poetry (2)
  38. Python - Poetry (4) Management Environment
  39. I collected Banhua's spatial data set in Python. In addition to meizhao, I found her other secrets again!
  40. I modified ban Hua's boot password in Python and found her secret after logging in again!
  41. After my girlfriend said good night to you, she was still online. I made a script in Python and successfully conquered it
  42. Python crawlers are used by you to climb sister pictures. We are ashamed to be with them!
  43. Python basic exercises, including answer analysis
  44. I used Python to capture the hot reviews of Wu's microblog events, chatting about technology and eating melons
  45. 60000 word summary of Python basic knowledge points, liver explosion, staying up late in a week [recommended collection]
  46. How do Python crawlers learn? Learn about the responsibilities of recruitment positions and see how much you can earn for your skills
  47. 20 lines of Python code crawl 2W multiple audio file materials [source code attached + detailed analysis] necessary for new media creation
  48. 微软开源浏览器自动化工具Playwright for Python(附源码)
  49. Python 中的进制转换
  50. Python 的算术运算符
  51. Python 的整数
  52. You love me, I love you. It's a headache for IP to be blocked [Python crawler practice: IP proxy JS reverse collection]
  53. Django learning knowledge points, road map, data summary, recommended collection!
  54. Headmaster Wang was hammered instead of flirting with his sister? No matter how rich you are, you just lick the dog [Python reptile actual combat: microblog comments]
  55. We are addicted to short videos and can't extricate ourselves? Python crawler advanced, take you to play short video
  56. How to learn Python Programming? Which books are suitable for beginners
  57. Python is so popular, what's the difference between it and other programming languages?
  58. Python web crawler - Jingdong Mall product list
  59. Django custom user model
  60. All the learning routes of Python and the knowledge system you want are here. Don't do useless work