Problems receiving arguments on a subprocess

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Problems receiving arguments on a subprocess

hidura
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.

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

Here is the code of the script:

"""
Created By: hidura
On Date: Jan 25, 2011
"""
from xml.dom.minidom import parseString
import os
import sys

class savCSS:
"""This class has to save
the changes on the css file.
"""

def __init__(self, args):

document = parseString(args)
request = document.firstChild

address = request.getElementsByTagName('element')[0]
newdata = request.getElementsByTagName('element')[1]

cssfl = open("/webapps/karinapp/Suite/"+address.getAttribute('value'), 'r')
cssData = cssfl.read()
cssfl.close()

dataCSS = ''
for child in newdata.childNodes:
if child.nodeType == 3:
dataCSS += child.nodeValue

nwcssDict = {}

for piece in dataCSS.split('}'):
nwcssDict[piece.split('{')[0]] = piece.split('{')[1]


cssDict = {}

for piece in cssData.split('}'):
cssDict[piece.split('{')[0]] = piece.split('{')[1]


for key in nwcssDict:
if key in cssDict == True:
del cssDict[key]

cssDict[key] = nwcssDict[key]


result = ''
for key in cssDict:
result += key+"{"+cssDict[key]+"}"


cssfl = open(cssfl.name, 'a')
cssfl.write(result)
cssfl.close()



if __name__ == "__main__":

print(sys.stdin.read())
savCSS(sys.stdin.read())


Thanks in advance
--
http://mail.python.org/mailman/listinfo/python-list
Reply | Threaded
Open this post in threaded view
|

Re: Problems receiving arguments on a subprocess

Chris Rebert-6
On Wed, Jan 26, 2011 at 3:27 PM,  <[hidden email]> 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
--
http://mail.python.org/mailman/listinfo/python-list
Reply | Threaded
Open this post in threaded view
|

Re: Problems receiving arguments on a subprocess

hidura
In reply to this post by hidura
The print line it doesn't print anything that's why i say is not
receiving anything.

2011/1/26, [hidden email] <[hidden email]>:

> 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.
>
> 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
>
> Here is the code of the script:
>
> """
> Created By: hidura
> On Date: Jan 25, 2011
> """
> from xml.dom.minidom import parseString
> import os
> import sys
>
> class savCSS:
> """This class has to save
> the changes on the css file.
> """
>
> def __init__(self, args):
>
> document = parseString(args)
> request = document.firstChild
>
> address = request.getElementsByTagName('element')[0]
> newdata = request.getElementsByTagName('element')[1]
>
> cssfl = open("/webapps/karinapp/Suite/"+address.getAttribute('value'), 'r')
> cssData = cssfl.read()
> cssfl.close()
>
> dataCSS = ''
> for child in newdata.childNodes:
> if child.nodeType == 3:
> dataCSS += child.nodeValue
>
> nwcssDict = {}
>
> for piece in dataCSS.split('}'):
> nwcssDict[piece.split('{')[0]] = piece.split('{')[1]
>
>
> cssDict = {}
>
> for piece in cssData.split('}'):
> cssDict[piece.split('{')[0]] = piece.split('{')[1]
>
>
> for key in nwcssDict:
> if key in cssDict == True:
> del cssDict[key]
>
> cssDict[key] = nwcssDict[key]
>
>
> result = ''
> for key in cssDict:
> result += key+"{"+cssDict[key]+"}"
>
>
> cssfl = open(cssfl.name, 'a')
> cssfl.write(result)
> cssfl.close()
>
>
>
> if __name__ == "__main__":
>
> print(sys.stdin.read())
> savCSS(sys.stdin.read())
>
>
> Thanks in advance
>

--
Enviado desde mi dispositivo móvil

Diego I. Hidalgo D.
--
http://mail.python.org/mailman/listinfo/python-list