Problems receiving arguments on a subprocess

Chris Rebert clp2 at rebertia.com
Wed Jan 26 20:24:36 EST 2011


On Wed, Jan 26, 2011 at 3:27 PM,  <hidura at gmail.com> wrote:
> Hello i am trying to make a subprocess that will have to send data as an
> arguments and is executing the script but don't receiving anything.

Command-line arguments, or stream/file input via stdin? I think you
mean the latter. The term "argument(s)" is not typically used to
describe the latter.

How exactly did you conclude that the script isn't receiving anything?

> Here is the code of the subprocess:
> car = Popen(shlex.split(self.block.getAttribute('cmd')),
> stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
> data = car.communicate(str("<request>"+self.extract.getByAttr(self.block,
> 'name', 'args')[0].toxml()+"</request>").encode())
>
> dataOut = data[0].decode()
> log = data[1].decode()
> print(dataOut)
>
> if car.returncode < 1:
> return dataOut.split('\n')
>
> else:
> print(log)
> return log

If you still have problems, try printing `log` unconditionally and
then checking that you still get no output.
Also, please ensure future posts preserve the indentation in your
code. It's rather annoying (and imprecise) to have to infer it.

> Here is the code of the script:
<snip>
>
> if __name__ == "__main__":
>
> print(sys.stdin.read())
> savCSS(sys.stdin.read())

You do realize the second .read() will *always* return an empty
string, right? The first .read() already read all of the stdin stream,
so there's nothing left for the second .read() to get. I suspect this
is the cause of your problem. Remove the line involving print().

Cheers,
Chris
--
http://blog.rebertia.com



More information about the Python-list mailing list