Friday, 15 July 2011

How to execute commands through pipe in Python? -


I search and use WC to get the total LO using the pipe. Find -name "* .cpp" -print | Xargs wc 44 109 896 ./main.cpp ... 288 1015 8319 ./src/util/util.cpp 733 2180 21494 Total

Let me automate the python I am getting with Required, I'll search. Xarg command many times, the process of obtaining the result and the total LOC

How can I execute the command pipe in Python? I tried it, but it does not return anything

  import subproduction p = subprances Popen (['search', '.', '-name', '* .cc ",' -print ',' | ',' xargs', '' Wc"], stdout = subprocess.PIPE, stderr = Subprocess.PIPE) out, err = p.communicate () print   

added

signal with Conneshchev, I can work it P2 = popen ( ['Search', '.', '-name', '* .cc ",' -print '], stdout = PIPE) [2] Xargs", "wc"], stdin = p1.stdout, stdout = PIPE ) P1.stdout.close () # If P2 exits, then allow P1 to get a SIGPIPE output = p2.communicate () [0] print output

You must connect two described Popen objects like it is.

But I would like to recommend, because it is very easy to use for such things.

No comments:

Post a Comment