LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 07-24-2015, 06:27 AM   #1
jiceq
LQ Newbie
 
Registered: Jul 2015
Posts: 14

Rep: Reputation: Disabled
Cannot launching app with python's subprocess.call method gives error


Hi,
i'm new to the forum and i hope u guys can help me out.

I'm working with centos 7 gnome desktop and i'm writing a python script that runs inside Autodesk Maya. All works well until the time when i want to launch programmatically a video player.

i'm doing this:

Code:
command6 = "gnome-terminal -x bash -c 'melt /home/jiceq/Desktop/pelota.mov;bash'"
subprocess.call(command6, shell=True, env=os.environ.copy(),stdout=PIPE)
The application is the melt video engine and if i type this on the command line:
Code:
melt /home/jiceq/Desktop/pelota.mov
the video starts correctly so it works perfectly from there. Conversely, if i do it from python it gives me an error.

Code:
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.


I'm quite convinced the configuration from the gnome-terminal is not the correct one. Maybe the command6 is incorrect.

I've tried to launch other installed programs and they fail to launch from python but not from the command line.

Can u give me a hint on this?

Maybe this isnt the right spot maybe it should be on programming forum...

Last edited by jiceq; 07-24-2015 at 09:08 AM.
 
Old 07-24-2015, 10:34 AM   #2
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 10,007

Rep: Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191Reputation: 3191
What happens when you type the command as you have it in the python script onto the command line?
Code:
bash -c 'melt /home/jiceq/Desktop/pelota.mov;bash'

# and then
gnome-terminal -x bash -c 'melt /home/jiceq/Desktop/pelota.mov;bash'
Also, it is a good practice in scripts to use the full path to a command to make sure the correct one is called.

the other thing to check would be where is LADSPA_PATH being set and is it available as you invoke bash several times in the call.
 
Old 07-24-2015, 11:38 AM   #3
dugan
LQ Guru
 
Registered: Nov 2003
Location: Canada
Distribution: distro hopper
Posts: 11,224

Rep: Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320Reputation: 5320
subprocess.call takes the command and its arguments as a list, not as a single string. So at the very least it should be:

Code:
command6 = ['gnome-terminal', '-x', 'bash', '-c', 'melt /home/jiceq/Desktop/pelota.mov;bash']
subprocess.call(command6, shell=True, env=os.environ.copy(),stdout=PIPE)
 
Old 07-24-2015, 01:52 PM   #4
Habitual
LQ Veteran
 
Registered: Jan 2011
Location: Abingdon, VA
Distribution: Catalina
Posts: 9,374
Blog Entries: 37

Rep: Reputation: Disabled
You said gnome terminal runs, but maya fails on
Code:
mlt_repository_init: failed to dlopen /usr/lib64/mlt/libmltavformat.so
so, create a shell script and use
#!/bin/bash
Stick env ($PATH) variables here.
/path/to/melt /home/jiceq/Desktop/pelota.mov

save and exit. chmod etc.
command6 = ['gnome-terminal', '-x', 'bash', '-c', '/home/x/script.sh']
subprocess.call(command6, shell=True, env=os.environ.copy(),stdout=PIPE)

Not to doubt dugan, but is shell=True even necessary if we open/exec/run a terminal emulator that opens a shell already?
Unless this for some visual feedback (cheap debugger?)

Doesn't seem very pythonic to me. But I'm new to the game.

Thanks.
 
Old 07-24-2015, 01:54 PM   #5
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Moved: This thread is more suitable in <PROGRAMMING> and has been moved accordingly to help your thread/question get the exposure it deserves.
 
Old 07-27-2015, 03:50 AM   #6
jiceq
LQ Newbie
 
Registered: Jul 2015
Posts: 14

Original Poster
Rep: Reputation: Disabled
Hi Guys,

Dugan, as far as i can tell since i searched for it on google, subprocess.call admits a string as the commands but will try your point as soon as i can since it seems safer and the right way to do it. I don't have much hope it will work since it's quite the same as the string but will try anyway just in case.

On the other hand my other problem is i dont know what's the configuration the shell loads when i launch it manually hence, i cannot be sure what ENV variables to add to the shell script or even if it is a problem of env variables.

I tried something like:

Code:
!#/bin/sh
source /etc/bashrc
source /etc/profile
melt "#@"
in the melt.sh
and the following:
Code:
command4 = "sh /home/rigging/Desktop/melt.sh /home/rigging/Desktop/pelota.mov"
subprocess.call(command4, shell=True, env=os.environ.copy(),stdout=PIPE)
but didn't work either.
 
Old 07-27-2015, 09:00 AM   #7
jiceq
LQ Newbie
 
Registered: Jul 2015
Posts: 14

Original Poster
Rep: Reputation: Disabled
Tried this as said:

Code:
command7 = ['gnome-terminal', '-x', 'bash', '-c', 'melt /home/jiceq/Desktop/pelota.mov;bash']
subprocess.call(command7, shell=False, env=os.environ.copy(),stdout=PIPE)
Had to set "shell=False" otherwise it only launches a terminal and nothing more.

The result is the same as i had with the string command:

Code:
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)
Maybe executing a shell script that previously loads proper configuration is the way to go.... Any ideas on this? I'm using Centos 7. It has to be something wrong with the terminal's config not being the same....

Last edited by jiceq; 07-27-2015 at 09:02 AM.
 
Old 07-28-2015, 05:10 AM   #8
jiceq
LQ Newbie
 
Registered: Jul 2015
Posts: 14

Original Poster
Rep: Reputation: Disabled
I've discovered something really interesting:

When i launch the terminal through subprocess.call it gives the error i previously posted. But then i tried to call the videoplayer manually in the same terminal and didn't work either, whereas if i open a new terminal it works.

Furthermore, i've discovered that if in that terminal i type "ldconfig" with root privileges and then i call manually de videoplayer.... it works!!!!!

So, my conclusion:

What is more precisely preventing the videoplayer to be launched is that the terminal's config does not recognize the path to the dynamic libraries, rebuilding the ld.so.cache makes it load and recognize the paths which is what ldconfig apparently does. The only problem is that it requires root permissions to write the cache.

So i got a pathway here, i only need to automate it through a script something like:

#!/bin/bash
sudo ldconfig
melt "!@"

and be able to do it without asking for a password. For this ive tried to edit the /etc/sudoers list and add my user but no chance!

You guys certainly know how to do this!! Any help?
 
Old 07-28-2015, 06:01 AM   #9
jiceq
LQ Newbie
 
Registered: Jul 2015
Posts: 14

Original Poster
Rep: Reputation: Disabled
guys this is driving me crazy, i think fate doesnt want me to get this through

My Python Script:
Code:
command8 = ['gnome-terminal', '-x', 'bash', '-c', 'sh /home/jiceq/Desktop/melt2.sh /home/jiceq/Desktop/pelota.mov;bash']
call(command8, shell=False, env=os.environ.copy(),stdout=PIPE)
My Sh Script:
Code:
#! /bin/bash

source /home/jiceq/.bashrc
source /home/jiceq/.bash_profile
sudo ldconfig
melt "#@"
The end of my sudoers file without any errors:
Code:
jiceq ALL=(ALL) NOPASSWD:/sbin/ldconfig
Result: Same error!!
But: if i login as root in that shell and run "ldconfig" and then run manually the videoplayer it works!

What's going on here??
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] python subprocess not working inside python script divyashree Programming 1 10-01-2014 07:33 AM
C++: Call super class virtual method from replacement method hydraMax Programming 4 05-01-2013 10:34 AM
Subprocess in Python giving error B Akshay Programming 7 02-14-2013 10:07 AM
python os.system() or subprocess.Popen() TypeError on ubuntu lucid 10.04 sahar.gh Programming 1 06-25-2012 07:56 PM
How can I script an autologin, automatically call kde(or simillar) and call an app aboaventura Slackware 8 02-03-2007 11:00 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration