When I run my python scripts I generally run with the console open just to keep an eye on things. I have a script that calls 3 external command line apps one after the other.
On one pc all output from these apps appears in the console window and is scrollable. On another pc a new console window opens in turn for each of the three apps, making it impossible to read what has been happening.
Both machines are identical in both software and hardware!
Any idea why?

Sorry this is a bit off-topic, but it is relevant to Python...

Recommended Answers

All 12 Replies

Maybe you could make the main script in Python and avoid being affected by setup issues. It is probably small difference how the .py extension is defined to be treated, assuming we are talking now about Windows system, not Linux etc Posix ones.

Another solution is to catch the apps output in your python program. You may need to change the way your apps are launched.

Another solution is to catch the apps output in your python program. You may need to change the way your apps are launched.

I would love to do this but have not got the first clue how! The apps give progress information that would be very nice to use in my gui but lots of googling has revealed very little on the subject.
The apps are launched using your own command module (or if I want the console to be very verbose I use os.system(app)).

Gribouillis do you have any suggestions for catching the apps output?
Thanks.

Gribouillis do you have any suggestions for catching the apps output?
Thanks.

Well, we don't have much information. What is your OS and version of python ? What are those apps that your program is starting ? Are they python apps ? Why doesn't your python code catch their output if you started them with my Command class ? You could also post some code, for example the lines surrounding the place where the apps are started, etc. All this would help.

Well, we don't have much information. What is your OS and version of python ? What are those apps that your program is starting ? Are they python apps ? Why doesn't your python code catch their output if you started them with my Command class ? You could also post some code, for example the lines surrounding the place where the apps are started, etc. All this would help.

OK. Windows xp. Python 2.7
The apps are neroaacenc.exe and x264.exe. Both are designed as cross-platform command-line apps, not python apps. I call x264 like this:

avc=<required paths and parameters>
Command(avc).run()

Command should look rather familiar to you:

class Command(object):
    """Run a command and capture it's output string, error string and exit status"""

    def __init__(self, command):
        self.command = command 

    def run(self, shell=True):
        process = subprocess.Popen(self.command, shell = shell, stdin=subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
        self.pid = process.pid
        self.output, self.error = process.communicate()
        self.failed = process.returncode
        return self

    @property
    def returncode(self):
        return self.failed

I don't know how to catch data, that is why I'm not doing it! I'm still very new to this.

Ok, try this

avc=<required paths and parameters>
com = Command(avc).run()
if com.output:
    print com.output
if com.error:
    print com.error
if com.failed:
    print "COMMAND FAILED: '{0}' !".format(avc)

Done.
The app (x264.exe) ran as usual, no errors.
The console window was empty throughout. The app displayed its progress in the title bar of the console, as usual. When the app finished it displayed its status, the same information that is present continually if I call the app with os.system.

Done.
The app (x264.exe) ran as usual, no errors.
The console window was empty throughout. The app displayed its progress in the title bar of the console, as usual. When the app finished it displayed its status, the same information that is present continually if I call the app with os.system.

That's good. The difficult part in windows is if you want to present the output continually in python. I'll try to post a general solution soon (although some solutions can already be found here and then).

The other thing is, does x264.exe pop up a new console ? If it does, it could probably be removed too. We could try to call subprocess.Popen() whith shell=False for example. For this you must post your whole command line.

Sounds complicated but I'm keen to learn.
No x264 doesn't open a new console window on this pc, but it does on my other one! and that takes us right back to the original question of this thread...!

No x264 doesn't open a new console window on this pc, but it does on my other one! and that takes us right back to the original question of this thread...!

If your command is x264 -foo bar baz , try this to see if changes anything

avc=['x264', '-foo', 'bar', 'baz']
com = Command(avc).run(shell=False)
if com.output:
    print com.output
if com.error:
    print com.error
if com.failed:
    print "COMMAND FAILED: '{0}' !".format(avc)

If your command is x264 -foo bar baz , try this to see if changes anything


I got to the bottom of the original question. For some reason the second pc was opening scripts with pythonw. So each time the external app finished it would close the console and open a new one for the next app. Whereas machine number 1 was opening scripts with python and everything was getting appended in the one console window!

So really this thread is dead, but I would like to learn more about getting the info from the console apps back into my python app, please, Gribouillis...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.