linux - piping a string to gcc with python's subprocess.Popen -


i have c++ style text file i'm trying pipe gcc remove comments. initially, tried regex approach, had trouble handling things nested comments, string literals , eol issues.

so i'm trying like:

strip_comments(test_file.c)  def strip_comments(text):     p = popen(['gcc', '-w', '-e', text], stdin=pipe, stdout=pipe, stderr=stdout)     p.stdin.write(text)     p.stdin.close()     print p.stdout.read() 

but instead of passing file, i'd pipe contents because files i'm trying preprocess don't have .c extension

has had success this?

this 1 works subprocess.pipe (os.popen() deprecated), , need pass , additional - argument gcc make process stdin:

import os subprocess import popen, pipe def strip_comments(text):     p = popen(['gcc', '-fpreprocessed', '-dd', '-e', '-x', 'c++', '-'],              stdin=pipe, stdout=pipe, stderr=pipe)     p.stdin.write(text)     p.stdin.close()     return_code = p.wait()     print p.stdout.read() 

Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -