Python

Moderators: None (Apply to moderate this forum)
Number of threads: 473
Number of posts: 1172

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Running exec file from python issue Posted by yohadd on 18 Jan 2005 at 3:12 AM
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




Report
Re: Running exec file from python issue Posted by infidel on 18 Jan 2005 at 1:21 PM
: 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?


infidel

$ select * from users where clue > 0
no rows returned





 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.