LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   python 2.6.4 os.popen os.system (https://www.linuxquestions.org/questions/programming-9/python-2-6-4-os-popen-os-system-791622/)

jabfinger 02-25-2010 09:00 PM

python 2.6.4 os.popen os.system
 
Hello,

I am trying to write a gui app with python2.6.4 and wx on win XP.
I am attempting to resize an image with Imagemagick from within the program using os.popen and os.system in a thread.

Code:

os.popen("mogrify -resize " + str(x) + "x" + str(y) + "!" + " images/static/" + my_ref + ".gif")
or

Code:

os.system("mogrify -resize " + str(x) + "x" + str(y) + "!" + " images/static/" + my_ref + ".gif")
they both work as far as resizing the image but when os.system is used a command shell opens during the mogrify and when os.popen is used the command shell does not show but the rest of the program freezes until mogrify is done.

I would prefer that the program did not freeze during this process and the command shell did not show.

I have tried using wx to scale the image but the scaled image looks crappy.

anyway is there a way to use os.system and not have the shell show?

thanks

pgpython 02-26-2010 05:21 AM

First of all there is a python module for ImageMagick. I am curious as to why you are using it through the os instead of through python?

There is no way to get os.system to do what you want it doesn't have that power. It's useful for when you need to make simple os calls like creating or removing a directory. If you need something I suggest subprocess which has a very good popen command that can easily be used to do what you want.

jabfinger 02-26-2010 10:22 AM

thanks pgpython,

In answer to your question about why. os.popen and Imigemagick are on the system now and pymagick is not. I guess I just do not want to install more stuff than I need or can get away with. I realy did not want to install Imagemagick either but resizing/scaling with wx was not cutting it
as far as image quality is concerned.

Both of the commands that I have listed work. I just thought perhapse there was a way that one or the other would do the work without holding up the program or displaying the shell. I am using os.popen in the same program to open notepad.exe as well, and though it holds up the rest of the program at this point I am glad because files wont be opened by the program during the editing with notepad.


All times are GMT -5. The time now is 06:40 PM.