Hello everyone!

just dumped bytes forums and joined daniweb... hope its a good decision :P

anyway, could you guys take a second to look at the following code...

import subprocess as sp

cmd = "awk '{print $0}'"

ex = sp.Popen(cmd.split(' '), stdin = sp.PIPE, stdout = sp.PIPE, stderr = sp.PIPE)

ot, et = ex.communicate('''abc

print ot
if et:
	print 'ERROR:'
	print et

So, if you have the least knowledge of awk, you can tell that all the piped input is supposed to be printed as output.
but what i instead get is this:

awk: 1: unexpected character '''
awk: line 2: missing } near end of file

what is that supposed to mean.. please help... any response is fine :)

thank you

Recommended Answers

All 4 Replies

I don't know about awk, but I what would happen if you changed

ot, et = ex.communicate('''abc


ot, et = ex.communicate('abc\ndef\nghi\njkl\nmno')

It just didn't seem to like something about the triple-quoted string. But of course I could be completely off seeing as I don't know anything about awk, but I thought I could suggest that one thing :P
Tell me if that change fixes the errors!

Hey, thanks for giving your thaughts...

but well, sadly its still the same error.. :(

I think the problem is in your arguments list for Popen:

>>> cmd = "awk '{print $0}'"
>>> cmd.split(' ')
['awk', "'{print", "$0}'"]

It should be ['awk', "'{print $0}'"] .

oooooooooooh dear mee!

how in the world did i miss that... i feel so stupid

thank you so much Gribouillis... i really owe you one :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, learning, and sharing knowledge.