ununderstandable behavior subprocess.Popen(cmd,std

2019-08-20 03:25发布

问题:

I use an external command inside a python script using firstly:

subprocess.Popen(cmd, stdout=subprocess.PIPE)

then i get the stdout.

The problem is that the result of this external command when executing it inside the script is not the same if i execute it directly in the command line.

I use then os.system(cmd), but the same problem.

Is this instructions in python use some buffers?

How can i explain the difference between the two results (command line and inside the script).

I'm using this tool as a local command from comman line after installing it:

https://potassco.org/clingo/run/

I use some file as input like this one:

edge("s1","s3").

edge("s2","s4").

edge("s3","s4").

path(X,Y) :- edge(X,Y). % x and y are strings

path(X,Z) :- path(X,Y), path(Y,Z).

:- path(X,Y), path(Y,X). %cyclic path.

To do it the tool generate a model like this :

edge("s1","s3") edge("s2","s4") edge("s3","s4") path("s1","s3") path("s2","s4") path("s3","s4") path("s1","s4")
SATISFIABLE

When i call the command inside my python script it doesn't compute all the model, it generate an incomplete model. This problem appear only in the big examples, which requires the computation of a large model . That's why i'm asking if this commands : subprocess.Popen and os.system use some buffers...