Running exec file from python issue - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Running exec file from python issue

yohaddyohadd Posts: 1Member
Hi,

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?

Thanks in advance
Yohad




Comments

  • infidelinfidel Posts: 2,900Member
    : Hi,
    :
    : 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?


    [size=5][italic][blue][RED]i[/RED]nfidel[/blue][/italic][/size]

    [code]
    $ select * from users where clue > 0
    no rows returned
    [/code]

Sign In or Register to comment.