: I trying to run exec file from python, and to get the output immediately to the screen and to variable, and also to get the return code.
: When I use the commnd "os.system(cmd)" ,I get the output to the screen, but I cant get it to variable ( I get only the return code );
: When I use the commnd "stat_output = commands.getstatusoutput(cmd)", I get the output and the return code to var.
: but if I want to get the output to the screen I need to wait until the command is ended.
: How can I get the output immediately to the screen, and also to var?
I'm not sure I understand your question completely. The command that you are running is probably writing to one place, the stdout stream. It seems reasonable to expect that the output will therefore only go to one or the other (console window or variable). If the python function redirects the command's stdout to capture it to a variable, then it won't be displayed in the console. And vice versa. In UNIX, this is where you would use the "tee" command, which essentially branches a stdout stream to two places. Perhaps the command line you are executing could use "tee" to pipe a copy of the output to a temporary file at the same time it is being displayed on the screen, then when the function returns with the return code, your script could read that temporary file to obtain a copy of the command's output?
$ select * from users where clue > 0
no rows returned