tags:

views:

67

answers:

1

Hi,

I have two processes.

  1. One processes is redirecting output of some unix command to a file on server side.The data is always appended to the file. e.g.

    find / > tmp.txt
    
  2. Another process is opening and reading the same file and storing it in a string and sending the entire string to the client.

Now, this things take simultaneously. I am using python.

Any suggestion as in what can be possible ways to implement this scenario. Please explain with sample code.

Thanks in advance.

Tazim.

+1  A: 

If what you want is having the Output of a Unix command in a file and displaying it at the same time, you can [tee][1] it to stdout and read it from there, like:

>>> command_line = '/bin/find / |tee tmp.txt'
>>> args = shlex.split(command_line)
>>> p = subprocess.Popen(args,stdout=subprocess.PIPE)

From there you can either use commuicate() or directly read the stdout from the POpen object. See how it can be used here.

Andre Bossard