Arjun18
Posts: 9
Joined: Sun May 04, 2014 9:32 am

Error please help. Permission denied

Fri Jul 18, 2014 1:31 pm

This is the program:
import time
import subprocess
repeat=True

try:
subprocess.call("endtask.py", timeout=1, shell=True)
except:
repeat=True

def end():
try:
subprocess.call("end.m3u", timeout=1, shell=True)
except:
repeat=True

def sanskar():
try:
subprocess.call("sanskar.m3u", timeout=1, shell=True)
except:
repeat=True
def sabras():
try:
subprocess.call("sabras.m3u", timeout=1, shell=True)
except:
repeat=True

while repeat:
print("Which radio station would you like")
radio=input()
if radio=="1":
print("You Selected Sanskar")
sanskar()
elif radio=="2":
print("You Selected Sabras")
sabras()
elif radio=="0":
print("You Have Ended Playback")
end()

When i run it on windows it works and opens VLC when a number is slected. On the rasberry pi when the number is pressed it says for exams You Slected Sanskar, but does not go on to open any program. Any ideas?

User avatar
PeterO
Posts: 5951
Joined: Sun Jul 22, 2012 4:14 pm

Re: Error please help. Permission denied

Fri Jul 18, 2014 1:48 pm

Arjun18 wrote:This is the program:

Code: Select all

import time
import subprocess
repeat=True

try:
    subprocess.call("endtask.py", timeout=1, shell=True)
except:
    repeat=True
    
def end():
    try:
        subprocess.call("end.m3u", timeout=1, shell=True)
    except:
        repeat=True

def sanskar():
    try:
        subprocess.call("sanskar.m3u", timeout=1, shell=True)
    except:
        repeat=True
def sabras():
    try:
        subprocess.call("sabras.m3u", timeout=1, shell=True)
    except:
        repeat=True

while repeat:
    print("Which radio station would you like")
    radio=input()
    if radio=="1":
        print("You Selected Sanskar")
        sanskar()
    elif radio=="2":
        print("You Selected Sabras")
        sabras()
    elif radio=="0":
        print("You Have Ended Playback")
        end()

When i run it on windows it works and opens VLC when a number is slected. On the rasberry pi when the number is pressed it says for exams You Slected Sanskar, but does not go on to open any program. Any ideas?
There, it makes more sence now....
PeterO
Discoverer of the PI2 XENON DEATH FLASH!
Interests: C,Python,PIC,Electronics,Ham Radio (G0DZB),1960s British Computers.
"The primary requirement (as we've always seen in your examples) is that the code is readable. " Dougie Lawson

DirkS
Posts: 10371
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Error please help. Permission denied

Fri Jul 18, 2014 2:10 pm

You'll probably use the full commandline, e.g. ''vlc sanskar.m3u'

Gr.
Dirk.

Arjun18
Posts: 9
Joined: Sun May 04, 2014 9:32 am

Re: Error please help. Permission denied

Fri Jul 18, 2014 2:18 pm

DirkS wrote:You'll probably use the full commandline, e.g. ''vlc sanskar.m3u'

Gr.
Dirk.
How do i do that

Arjun18
Posts: 9
Joined: Sun May 04, 2014 9:32 am

Re: Error please help. Permission denied

Fri Jul 18, 2014 2:58 pm

How do i change the permissions, i change them and press ok. When i go back into it, they havnt changed

DirkS
Posts: 10371
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Error please help. Permission denied

Fri Jul 18, 2014 3:04 pm

Arjun18 wrote:How do i change the permissions, i change them and press ok. When i go back into it, they havnt changed
Is this related to your original question? If not please start a new topic.
Also, it's not clear what permissions you're trying to change, how / where you're trying to change them and where you go back into...

Gr.
Dirk.

Arjun18
Posts: 9
Joined: Sun May 04, 2014 9:32 am

Re: Error please help. Permission denied

Fri Jul 18, 2014 3:09 pm

DirkS wrote:
Arjun18 wrote:How do i change the permissions, i change them and press ok. When i go back into it, they havnt changed
Is this related to your original question? If not please start a new topic.
Also, it's not clear what permissions you're trying to change, how / where you're trying to change them and where you go back into...

Gr.
Dirk.
yes it is im trying to change the permission of sanskar.m3u so python can open it. But i change it, press ok, go back into it, and it hasnt changed.

DirkS
Posts: 10371
Joined: Tue Jun 19, 2012 9:46 pm
Location: Essex, UK

Re: Error please help. Permission denied

Fri Jul 18, 2014 3:16 pm

yes it is im trying to change the permission of sanskar.m3u so python can open it
I don't think that's really the issue here. In Win the extension m3u is linked to VLC.
I doubt if that's also the case on the Pi. What happens if you open / start (double click) an M3U file on the pi?

Gr.
Dirk.

Arjun18
Posts: 9
Joined: Sun May 04, 2014 9:32 am

Re: Error please help. Permission denied

Fri Jul 18, 2014 6:27 pm

DirkS wrote:
yes it is im trying to change the permission of sanskar.m3u so python can open it
I don't think that's really the issue here. In Win the extension m3u is linked to VLC.
I doubt if that's also the case on the Pi. What happens if you open / start (double click) an M3U file on the pi?

Gr.
Dirk.
It opens in VLC as i have downloaded and installed it on the pi. I get a permission error when i do it from python.

User avatar
jojopi
Posts: 3274
Joined: Tue Oct 11, 2011 8:38 pm

Re: Error please help. Permission denied

Sat Jul 19, 2014 8:47 am

subprocess.call() cannot open a data file, it can only execute a program or command like you would type in a terminal.

Putting just "endtask.py" in a terminal (or a subprocess.call) will only work if the file is executable, starts with "#!/usr/bin/python", and is installed in a directory on your search PATH, such as /home/pi/bin.

For a script that is in the current directory, the command needs to be "./endtask.py", and for a script that is not executable you need "python endtask.py".

A .m3u file cannot easily be made executable. As suggested earlier in the thread, a more syntactically valid command would be "vlc sanskar.m3u". However, even that does not do what you appear to want. It does not change the playlist for any existing vlc; it starts a new instance playing the new playlist in parallel. And the Python code will not continue until the command named in subprocess.call has finished.

If you want to control an existing vlc instance using Python, I think you need to look at something like https://wiki.videolan.org/Python_bindings

Arjun18
Posts: 9
Joined: Sun May 04, 2014 9:32 am

Re: Error please help. Permission denied

Sat Jul 19, 2014 3:22 pm

jojopi wrote:subprocess.call() cannot open a data file, it can only execute a program or command like you would type in a terminal.

Putting just "endtask.py" in a terminal (or a subprocess.call) will only work if the file is executable, starts with "#!/usr/bin/python", and is installed in a directory on your search PATH, such as /home/pi/bin.

For a script that is in the current directory, the command needs to be "./endtask.py", and for a script that is not executable you need "python endtask.py".

A .m3u file cannot easily be made executable. As suggested earlier in the thread, a more syntactically valid command would be "vlc sanskar.m3u". However, even that does not do what you appear to want. It does not change the playlist for any existing vlc; it starts a new instance playing the new playlist in parallel. And the Python code will not continue until the command named in subprocess.call has finished.

If you want to control an existing vlc instance using Python, I think you need to look at something like https://wiki.videolan.org/Python_bindings
Hi thanks for your answer. I went on to use this and tweaked it a little more to, subprocess.Popen. and also went on to change the settings in VLC to allow only one instance.

Return to “Troubleshooting”