How to launch command line app through a maya python script

python

#1

Hi,
due to some requests from the animation department i ve spent a lot of time trying to install and test some linux videoplayers like vlc, openshot, djv, smplayer, banshee, etc.

I’ve come to the conclusion that only the “melt” video engine meets all the requirements. But there is a downside: it has no GUI!!

we have to launch the video player like this: “melt <video1> <video2>” by typing this on the gnome-terminal

Ive made a maya GUI with python and pyside and my only concern now is launching the melt video player by pressing a GUI button.

So far i’ve tried:

command="melt path/to/video1"
subprocess.call(shlex.split(command), shell=True)

also tried with:

command="/usr/local/bin/melt path/to/video1"

also with Popen and system but can’t seem to get the correct grammar.

Also i’m thinking that maybe the problem is that i can’t run this as a maya subprocess, but that’s only an intuition.

Can you guys give me a hint?

Thanks.


#2

Update: i’m able to launch gedit and other videoplayers using:

command=“gedit”
subprocess.call(command, shell=True)

But this fails to work with melt… gosh but why does it not work if it works through the gnome terminal!!


#3

try using an absolute path to your executable. If it’s a windowed app you can probably also try it without shell=true


#4

[QUOTE=jiceq;28225]Update: i’m able to launch gedit and other videoplayers using:

command=“gedit”
subprocess.call(command, shell=True)

But this fails to work with melt… gosh but why does it not work if it works through the gnome terminal!![/QUOTE]

Hi,

For the Popen grammar, this works for me :

save = subprocess.Popen([B][[/B]self.pathToAfter, "-r", self.JSX['save'][B]][/B])
        save.communicate()# use this to wait for your subprocess to complete before continuing the rest of your script

My self.pathToAfter is an absolute path to my executable as Theodox suggested.
Hope this helps !

Victor


#5

Hello guys,
thanks for your suggestions what appears to be working partly at least is the following in my case:

command2 = "gnome-terminal -x bash -c '/usr/local/bin/melt /home/rigging/Desktop/pelota.mov;bash'"
subprocess.call(command2, shell=True, stdout=PIPE)

This opens a terminal and apparently runs the command but gives me the following error:

mlt_repository_init: failed to dlopen /usr/lib64/mlt/libmltavformat.so
  (/lib64/libavfilter.so.4: symbol sws_isSupportedEndiannessConversion, version LIBSWSCALE_2 not defined in file libswscale.so.2 with link time reference)
No LADSPA plugins were found!

Check your LADSPA_PATH environment variable.
bash: line 1: 12447 Segmentation fault      (core dumped) /usr/local/bin/melt /home/rigging/Desktop/pelota.mov

I don’t understand why if i run it manually from the terminal it opens a window and plays the video and conversely if i launch from python i get that error…


#6

Hi jiceq:

Try copying your current os.environ (os.environ.copy) and pass that to your subprocess call with the env argument. Seems like your python interpreter is launching the subprocess with a different set of environment variables than your OS and thus it’s failing to launch.


#7

[QUOTE=sonictk;28241]Hi jiceq:

Try copying your current os.environ (os.environ.copy) and pass that to your subprocess call with the env argument. Seems like your python interpreter is launching the subprocess with a different set of environment variables than your OS and thus it’s failing to launch.[/QUOTE]

Hi Sonictk, that sounded like the correct answer and i tried it but still no change.
I’ve tested in another machine that didn’t have openshot previously installed (it relies on melt-0.9.0 under the hood) and i have discovered that my install of melt-0.9.2 was lacking some packages that were provided by the openshot installation so my guess is melt is playing the videos through the command line (once openshot installed) by luck because I hadn’t provided the right packages first.

Still without an answer about why it works on the terminal and why i get the error with subprocess.call with env=os.environ.copy() set.


#8

I’m digging more in the fact that maybe the gnome shell i’m launching through python has a different configuration than the default one. I agree with Sonitck the two configurations may not be the same.

So, im trying to make an sh script like this:

#!/bin/bash

source /etc/profile
source /etc/bashrc
melt "[email protected]"

where the last line is where i call the melt video player engine.
The previous lines are meant to load all the configuration the default gnome-terminal has but i guess it lacks some other files or maybe the way i’m invoking is not the correct one:

command6 = "gnome-terminal -x bash -c 'sh /home/animation.thethinklab/Desktop/melt2.sh /home/animation.thethinklab/Desktop/pelota.mov;bash'"

Truth is my knowledge regarding linux is limited


#9

Since i managed to work this out i will answer myself:

The solution was to UNSET some of the environment variables such as LD_LIBRARY_PATH, PYTHONPATH, PYTHONHOME, etc so it gets like this:

command8 = ['gnome-terminal','-x', 'bash', '-c', "unset PATH;unset LD_LIBRARY_PATH;unset PYTHONPATH;unset PYTHONHOME;/usr/local/bin/melt " + string_list_of_blank_space_separated_files + ";bash"]
        call(command8, shell=False, env=os.environ.copy())