Skip to main content

Posts

Showing posts from September, 2017

python process real time output

Real Time Output Issue resolved: I did encountered similar issue in Python, while capturing the real time output from c program. I added " fflush(stdout) ;" in my C code. It worked for me. Here is the snip the code << C Program >> #include <stdio.h> void main () { int count = 1 ; while ( 1 ) { printf ( " Count %d\n" , count ++); fflush ( stdout ); sleep ( 1 ); } } << Python Program >> #!/usr/bin/python import os , sys import subprocess procExe = subprocess . Popen ( ".//count" , shell = True , stdout = subprocess . PIPE , stderr = subprocess . PIPE , universal_newlines = True ) while procExe . poll () is None : line = procExe . stdout . readline () print ( "Print:" + line ) << OUTPUT>> Print: Count 1 Print: Count 2 Print: Count 3 UPDATE:: The above one has flaws as we are reading only oneline per poll iteratio

Starting a simple Web server

Looked around to have some simple way of getting a web server up on linux/mac. Python: With python 5.4 there is  a simple web server that it can run. Command to launch HTTP server with python: python -m SimpleHTTPServer This will use the document root top as the current directory. Php: with python 5.4 there is web server that is default built in. Command: php -S 127.0.0.1:80 -t . This will launch the webserver with document root as "."