【发布时间】:2011-08-10 08:10:06
【问题描述】:
我正在尝试在 python 中编写代码,该代码将从顶部获取一些信息并将其放入文件中。 我只想写下应用程序的名称并生成文件。我遇到的问题是我无法获得 pidof 命令的输出,因此我可以在 python 中使用它。我的代码如下所示:
import os
a = input('Name of the application')
val=os.system('pidof ' + str(a))
os.system('top -d 30 | grep' + str(val) + '> test.txt')
os.system('awk '{print $10, $11}' test.txt > test2.txt')
问题是 val 总是有 0 但命令返回我想要的 pid。任何输入都会很棒。
【问题讨论】:
-
你有应用程序的名称,你想要...什么?将有关此应用程序的内容写入文件?
标签: python bash operating-system command