Access Denied when launching a Shell file

Post

Posted
Rating:
#1 (In Topic #1165)
Avatar
Regular
sarpomira is in the usergroup ‘Regular’
Hi All,

When the "Launch" button is pressed, this code would launch an external Python script.
It worked just fine for some time. Now whenever I try to get Gambas3 to run an external Python file (any file),
I get the error message shown below referring to : Permission denied.

Does anyone have an idea why this happens and what may be the solution?

Code (gambas)

  1. public sub cmd_Launch()
  2.  
  3.   'Path to the external Python Script  
  4.   'Specify the path to run the Python script
  5.   Dim FileAppPath As String
  6.   FileAppPath = "/home/veggie/Desktop/CallOptionCalc/python3/DoAnalysis.py"
  7.  
  8.   'Launch the external application
  9.    Shell FileAppPath
  10.  

ERROR MESSAGE in the debug window….
/bin/sh: 1: /home/veggie/Desktop/CallOptionCalc/python3/DoAnalysis: Permission denied
Online now: No Back to the top

Post

Posted
Rating:
#2
Avatar
Regular
thatbruce is in the usergroup ‘Regular’
What happens if you run that exact string in a terminal?

Online now: No Back to the top

Post

Posted
Rating:
#3
Guru
BruceSteers is in the usergroup ‘Guru’

sarpomira said

Hi All,

When the "Launch" button is pressed, this code would launch an external Python script.
It worked just fine for some time. Now whenever I try to get Gambas3 to run an external Python file (any file),
I get the error message shown below referring to : Permission denied.

Does anyone have an idea why this happens and what may be the solution?

Code (gambas)

  1. public sub cmd_Launch()
  2.  
  3.   'Path to the external Python Script  
  4.   'Specify the path to run the Python script
  5.   Dim FileAppPath As String
  6.   FileAppPath = "/home/veggie/Desktop/CallOptionCalc/python3/DoAnalysis.py"
  7.  
  8.   'Launch the external application
  9.    Shell FileAppPath
  10.  

ERROR MESSAGE in the debug window….
/bin/sh: 1: /home/veggie/Desktop/CallOptionCalc/python3/DoAnalysis: Permission denied

is the files executable flag set?
If not you'll have to use
Shell "python " & FileAppPath
or Exec ["python", FileAppPath]

or make it executable for it's shebang line to work as expected.
chmod +x /home/veggie/Desktop/CallOptionCalc/python3/DoAnalysis.py
Online now: No Back to the top

Post

Posted
Rating:
#4
Guru
BruceSteers is in the usergroup ‘Guru’
PS. is your Shell using bash or sh?  by default it uses sh but it can be better with bash

Change the Shell your app uses to bash like this..

Code (gambas)

  1. System.Shell = System.Find("bash")
  2.  


but often when an archive is unpacked somewhere all the +x flags get removed from scripts. (it's probably just that) using the python command to launch them or making the scripts executable should fix it for you.

Code (gambas)

  1.  
  2. ' check if file is executable and set x flag if not...
  3. If not InStr(Stat(FileAppPath).Perm.User, "x") Then Exec ["chmod", "+x", FileAppPath] Wait
  4.  
  5. ' Now try it
  6. Shell FileAppPath
  7.  
Online now: No Back to the top

Post

Posted
Rating:
#5
Avatar
Regular
sarpomira is in the usergroup ‘Regular’
I simplified the troubleshooting as much as possible and added two test lines as suggested by Bruce.
I created a "Hello World" script called Hello.py and placed it on the desktop.( It runs fine in the linux shell)
When I call the file from Gambas using "Shell" I get the following error.

/home/veggie/Desktop/Hello.py: 1: Syntax error: word unexpected (expecting ")")
I don't know if this is a Gambas error or an OS error.?

Code (gambas)

  1. Public Sub cmdRun_Click()
  2.  
  3.    'Path to the external Python Script  
  4.    Dim FileAppPath As String
  5.    
  6.   'Specify the command to run the Python script
  7.    FileAppPath = "/home/veggie/Desktop/Hello.py"
  8.  
  9.   'check if file is executable and set x flag if not...
  10.   'if Not InStr(Stat(FileAppPath).Perm.User, "x") Then Exec ["chmod", "+x", FileAppPath] Wait
  11.  
  12.   'Launch the external application
  13.    Shell FileAppPath
  14.    
  15.   'Shell "python" & FileAppPath
  16.  

PS: I ran the program with the various "chmod" and Shell lines shown above but the result is still "access denied" or   expecting ")"
Online now: No Back to the top

Post

Posted
Rating:
#6
Guru
BruceSteers is in the usergroup ‘Guru’
I'm only getting access denied if the executable flag is not set.
I just made a quick helloworld.py in $HOME
<HIGHLIGHT highlight="python">

#!/usr/bin/env python
print ("hello world")

</HIGHLIGHT>

Terminal went like this..

Code

bonus:~$ ~/helloworld.py
bash: /home/bonus/helloworld.py: Permission denied
bonus:~$ chmod +x ~/helloworld.py
bonus:~$ ~/helloworld.py
hello world

And running Shell "~/helloworld.py" in gambas printed "hello world" to console as expected.

Does the file in question have a shebang line as it's first line?
#!/usr/bin/env python

If it is something normally launched by something else the something else may know it is a python script and a shebang line was never added.
if not it will need to be run explicitly with python.

Ps. your commented Shell command
  'Shell "python" & FileAppPath

Should be
  'Shell "python " & FileAppPath
(a space after python)

You could maybe do some manual handling..

Code (gambas)

  1.  
  2.  Select LCase(File.Ext(FileAppPath))
  3.    Case "py"
  4.      Exec ["python", FileAppPath] Wait
  5.    Case "gbs"
  6.      Exec ["gbs3", FileAppPath] Wait
  7.    Case Else
  8.      Exec [FileAppPath] Wait
  9.  
  10.  If Process.LastValue Then
  11.    Message.Error(FileAppPath & "\nReturned error code " & Process.LastValue)
  12.  

Something like that ?
Online now: No Back to the top

Post

Posted
Rating:
#7
Guru
BruceSteers is in the usergroup ‘Guru’
Did your python hello world use parentheses?

that'd be a "you" error  ;)

print "hello world"
that's wrong with python

print ("hello world")
that's correct.
Online now: No Back to the top
1 guest and 0 members have just viewed this.