top button
Flag Notify
    Connect to us
      Facebook Login
      Site Registration Why to Join

Facebook Login
Site Registration
Print Preview

How to embed the output of a Subprocess embedded in curses window using Python

0 votes

Does any one have a good solution for how to embed the output of a subprocess (ex. subprocess.Popen("htop", stdout=subprocess.PIPE)) into an ncurses window? So for example, the terminal window is broken up into quadrants and the top right has htop running inside. I'd imagine this would involve some kind of terminal emulation as the dimensions of the window would need to be queried by htop.

posted Aug 14, 2013 by Satish Mishra

Looking for an answer?  Promote on:
Facebook Share Button Twitter Share Button Google+ Share Button LinkedIn Share Button Multiple Social Share Button

Similar Questions
+2 votes

I am using the Linux system with python, i am running the following script


import threading

import time

import sys
import subprocess
import datetime
import os
import time
import logging


In this script i am calling the other script named which is located on the desktop with 64 and abc as its arguments I am getting the following error

File "/usr/lib64/python2.6/", line 589, in __init__
 raise TypeError("bufsize must be an integer")
TypeError: bufsize must be an integer

Can someone help me?

0 votes

I've got a simple script that counts the number of words in a data set (it's more complicated than that, but that's one of the functions), but there are so many words that the output is too much to see in the command prompt window. What I'd like to be able to do is incorporate the "More..." feature that help libraries have, but I have no idea how to do it. I also don't know if I'm asking the question correctly because a Google search yielding nothing.

+1 vote

I have about 500 search queries, and about 52000 files in which I have to find all matches for each of the 500 queries.

How should I approach this? Seems like the straightforward way to do it would be to loop through each of the files and go line by line comparing all the terms to the query, but this seems like it would take too long.

Can someone give me a suggestion as to how to minimize the search time?

+1 vote

I want to find the maximal number of elements contained in a nested dictionary, e.g.

data = {
 'col1': {'err': [elem1, elem2, elem3]},
 'col2': {'err': [elem1, elem2]}

so to find the maximal number of elements in the lists for key 'err' in key 'col1' and 'col2'. Also key 'violations' may contain many keys (e.g. 'col1' , 'col2', 'col3' etc), so what's the best way to do this (using a loop)?

max = 0for col in data.violations:
 if max < len(data.violations.col.err):
 max = len(data.violations.col.err)
+1 vote

Let's say I want to compare two csv files: file A and file B. They are both similarly built - the first column has product IDs (one product per row) and the columns provide some stats about the products such as sales in # and $.

I want to compare these files - see which product IDs appear in the first column of file A and not in B, and which in B and not A.
Finally, it would be very great if the result could be written into two new CSV files - one product ID per row in the first column. (no other data in the other columns needed)

This is the script I tried:

import csv

#open CSV's and read first column with product IDs into variables pointing to lists
A = [line.split(',')[0] for line in open('Afile.csv')]
B = [line.split(',')[0] for line in open('Bfile.csv')]

#create variables pointing to lists with unique product IDs in A and B respectively 
inAnotB = list(set(A)-set(B))
inBnotA = list(set(B)-set(A))

print inAnotB
print inBnotA

c = csv.writer(open("inAnotB.csv", "wb"))

d = csv.writer(open("inBnotA.csv", "wb"))

print "done!" 

But it doesn't produce the required results.
It prints IDs in this format:


and nothing to the csv files.

Useful Links with Similar Problem
Contact Us
+91 9880187415
#280, 3rd floor, 5th Main
6th Sector, HSR Layout
Karnataka INDIA.