Hi Pythoneers,
I am trying to make my own gui for mencoder.exe (windows port of the
terrific linux mencoder/mplayer) to convert divx to Pocket_PC size.
My current app creates a batch script to run the mencoder with the needed
params, but now I want to integrate mencoder as a subprocess in my app.
What already works:
the starting of the subprocess.Pope n
and the subsequent killing of the process if I want it to.
My gui does not freeze up as it did in my first tries.
What I want to know (what does not yet work ;-)):
- Redirecting the output of the subprocess to a textwidget in my GUI
Any example or help is much appreceated.
I tried the subprocess.PIPE but I think I don't really understand how it is
suppost to work
The redirecting to a file does work but this not my objective...
So I'm stuck..... HELP
The started processes are long and I want to be able to show some kind of
progress-status.
Thanx,
Ivo Woltring 4 5088
Ivo, my initial thought would be, you need to know how much text you
will get back from popen. My Python reference has the following
example:
import os
dir = os.popen('ls -al', 'r')
while (1):
line = dir.readline()
if line:
print line,
else:
break
that example shows how to capture the process output in a file-type
object, then bring it into a string with readline().
in your app, you could create a Tkinter stringVar, say myOutput, for
the process output. In your Tkinter widget, you could then set a
textvariable=my Output. also use the wait_variable and watch options
(hope I recall these correctly, don't have my Tkinter ref. at hand) to
detect when there's been a change to the contents of the StringVar and
update the contents of the label.
Hope this helps, if not, write back.
cheers
S
<st************ ***@gmail.com> wrote in message
news:11******** *************@z 14g2000cwz.goog legroups.com... Ivo, my initial thought would be, you need to know how much text you will get back from popen. My Python reference has the following example:
import os dir = os.popen('ls -al', 'r') while (1): line = dir.readline() if line: print line, else: break
that example shows how to capture the process output in a file-type object, then bring it into a string with readline().
[.... snip ....] cheers S
Thanx for trying Stewart,
but that is not what I need
The output of mencoder is not readable with readlines (i tried it) because
after the initial informational lines You don't get lines anymore (you get a
linefeed but no newline)
The prints are all on the same line (like a status line)
something like
Pos: 3,1s 96f ( 0%) 42fps Trem: 0min 0mb A-V:0,038 [171:63]
which is coninually updated while the process runs...
in your app, you could create a Tkinter stringVar, say myOutput, for the process output. In your Tkinter widget, you could then set a textvariable=my Output. also use the wait_variable and watch options
How does this work? wait?? anyone?
(hope I recall these correctly, don't have my Tkinter ref. at hand) to detect when there's been a change to the contents of the StringVar and update the contents of the label. Hope this helps, if not, write back.
I really like to know how I can catch the output of a subproces.Popen ()
command and redirect it to something else (like a textwidget )
and I really like to use the subprocess module (standard in v2.4) to get to
know it.
Another reason to use the subprocess module is I can stop the process
because I know the handle of the thread. The subprocess module knows all
this.
cheerz,
Ivo.
Ivo Woltring wrote: The output of mencoder is not readable with readlines (i tried it) because after the initial informational lines You don't get lines anymore (you get a linefeed but no newline) The prints are all on the same line (like a status line) something like Pos: 3,1s 96f ( 0%) 42fps Trem: 0min 0mb A-V:0,038 [171:63]
Have you tried popen3 with stdout and stderr?
hth
Paul
Ivo Woltring wrote: The output of mencoder is not readable with readlines (i tried it) because after the initial informational lines You don't get lines anymore (you get a linefeed but no newline) The prints are all on the same line (like a status line) something like Pos: 3,1s 96f ( 0%) 42fps Trem: 0min 0mb A-V:0,038 [171:63]
Hm, I'm inferring that what you mean is that you get a carriage return
(ASCII 0x0C) but no linefeed (ASCII 0x0A) -- CR returns you to the
beginning of the current line, and LF advances you to the next line.
Rather than using readlines(), you could simply read() a few
characters (or a single character) at a time, buffering it yourself
and passing it on when you see the CR.
You're likely to run into I/O blockage issues no matter how you do
this, though -- even if you're reading a single character at a time,
read(1) won't return until you've read that character, and if the
program on the other end of the pipe isn't writing anything, then your
app is stuck. The "simple" way to do this is by using an i/o thread,
which does something like this:
buffer = []
while 1:
char = outpipe.read(1)
if char == '\0x0A':
notify_gui_thre ad( ''.join(buffer) )
buffer = []
else:
buffer.append(c har)
if StopEvent.IsSet ():
raise CustomStopExcep tion
Note that you don't want to try to update your GUI widgets directly
from the worker (i/o) thread -- very few GUI toolkits are threadsafe,
so you need to make all GUI calls from a single thread.
Jeff Shannon
Technician/Programmer
Credit International This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Stewart Midwinter |
last post by:
this has me puzzled; I've created a small test app to show the problem
I'm having.
I want to use subprocess to execute system commands from inside a
Tkinter app running under Cygwin.
When I open a python interpreter and run my subprocess command, all is
well. But when I run the same command from inside a Tkinter app, I'm
getting errors.
|
by: nholtz |
last post by:
Is there any way to delete a widget (window) from a Text widget, and
then add it back
to the Text, without re-creating the original widget. For example, I
think I would like to do
something like the following:
##########################################################
from Tkinter import *
root = Tk()
|
by: Gigs_ |
last post by:
I'm writing text editor.
How to enable/disable (cut, copy etc.) when text is selected/not selected
|
by: Ratko |
last post by:
Hi all,
I have a python gui app that launches multiple applications using
subprocess.Popen class and prints their output in the gui (using
PIPEs, threads and wxPython). Everything works great but the problem
is that some applications should run in the background (ie they don't
close when the gui closes) so next time when you start the gui it will
not have a handle on those processes that are still running and
therefore won't be able to...
|
by: bhunter |
last post by:
Hi,
I've used subprocess with 2.4 several times to execute a process, wait
for it to finish, and then look at its output. Now I want to spawn
the process separately, later check to see if it's finished, and if it
is look at its output. I may want to send a signal at some point to
kill the process. This seems straightforward, but it doesn't seem to
be working.
Here's my test case:
| |
by: Harishankar |
last post by:
Hi,
Sorry to start off on a negative note in the list, but I feel that the Python
subprocess module is sorely deficient because it lacks a mechanism to:
1. Create non-blocking pipes which can be read in a separate thread (I am
currently writing a mencoder GUI in Tkinter and need a full fledged process
handler to control the command line and to display the progress in a
text-box)
|
by: rparimi |
last post by:
I am trying to redirect stderr of a process to a temporary file and
then read back the contents of the file, all in the same python
script. As a simple exercise, I launched /bin/ls but this doesn't
work:
#!/usr/bin/python
import subprocess as proc
import tempfile
name = tempfile.NamedTemporaryFile(mode='w+b')
print 'name is '+ name.name
|
by: Jeremy Banks |
last post by:
Hi. I wondered if anyone knew the rationale behind the naming of the
Popen class in the subprocess module. Popen sounds like the a suitable
name for a function that created a subprocess, but the object itself is
a subprocess, not a "popen". It seems that it would be more accurate to
just name the class Subprocess, can anyone explain why this is not the
case?
Thank you.
|
by: Chuckk Hubbard |
last post by:
If I run 'python -i subprocessclient.py' I expect to see the nice
level of it go up 2, and the nice level of the subprocess go up 1.
But all I see is the nice level of the client change. What am I doing
wrong?
subprocessserver.py:
----------------------------
#!/usr/bin/python2.5
import os
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
| |
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules.
He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms.
Adolph will...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: TSSRALBI |
last post by:
Hello
I'm a network technician in training and I need your help.
I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs.
The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols.
I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |