获得进程的PID [英] getting a process's PID

查看:96
本文介绍了获得进程的PID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,


我想让python给我一个进程的PID(在这种情况下是

HUB)。我有它的工作,除了输出包括

\ 012(换行)。有没有办法让python不给我换行?


Python 1.4(1997年10月14日)[C]

版权所有1991-1995 Stichting Mathematisch Centrum,Amsterdam


>> import os
g = os.popen (" ps -ef | grep HUB | grep -v grep | awk''{print $ 2}''")
h = g.readlines()
g.close()
h



[''87334 \ 012'']


谢谢任何指导都是先进的。


-

随机生成的签名

无论谁说什么也不可能从未试过砰然关上一扇旋转门。

解决方案

2}''")
h = g.readlines()
g.close()
h



[''87334 \ 012'']


谢谢提前任何指导。


-

随机生成的签名

谁说什么都不可能从来没有试过砰然关上一扇旋转门。

"埃尔多拉多" < el ****** @ io.com写信息

新闻:20 ******************* @ eris.io。 com ...


你好,


我想让python给我一个进程的PID(在这个案子

HUB)。我有它的工作,除了输出包括

\ 012(换行)。有没有办法让python不给我换行?


Python 1.4(1997年10月14日)[C]

版权所有1991-1995 Stichting Mathematisch Centrum,Amsterdam


> import os
g = os.popen(" ps -ef | grep HUB | grep -v grep | awk''{print


2}''")
h = g.readlines()
g.close()
h



[''87334 \ 012'']



那里这不止一种方法! (哦,对不起,那是'Perl ......)


两种最标准的方法是在你的字符串上调用strip()来获得

一个没有领先和试验空白的空间


print h.strip()


或者如果你确切地知道你有什么(即,你不想要的换行是

只是最后一个字符),你可以摆脱它:


h = h [: - 1]

HTH,

-ej


Hello,

I am trying to get python to give me the PID of a process (in this case
HUB). I have it working, except for the fact that the output includes
\012 (newline). Is there a way to ask python not to give me a newline?

Python 1.4 (Oct 14 1997) [C]
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam

>>import os
g = os.popen("ps -ef | grep HUB | grep -v grep | awk ''{ print $2 }''")
h = g.readlines()
g.close()
h

[''87334\012'']

Thanks in advanced for any guidance.

--
Randomly generated signature
Whoever said nothing is impossible never tried slamming a revolving door.

解决方案

2 }''")
h = g.readlines()
g.close()
h

[''87334\012'']

Thanks in advanced for any guidance.

--
Randomly generated signature
Whoever said nothing is impossible never tried slamming a revolving door.


"eldorado" <el******@io.comwrote in message
news:20*******************@eris.io.com...

Hello,

I am trying to get python to give me the PID of a process (in this case
HUB). I have it working, except for the fact that the output includes
\012 (newline). Is there a way to ask python not to give me a newline?

Python 1.4 (Oct 14 1997) [C]
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam

>import os
g = os.popen("ps -ef | grep HUB | grep -v grep | awk ''{ print


2 }''")
h = g.readlines()
g.close()
h

[''87334\012'']


There''s more than one way to do it! (Oh, sorry, that''s Perl...)

The two most standard ways would be to call strip() on your string to get
one sans both leading and trialing whitespace

print h.strip()

or if you know exactly what you''ve got (i.e., the newline you don''t want is
just the last character), you can just get rid of it:

h = h[:-1]
HTH,
-ej


这篇关于获得进程的PID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆