# pi execute python script from shell

**URL:** <https://forum.xojo.com/t/pi-execute-python-script-from-shell/42383>\
**Category:** Raspberry Pi\
**Created:** [March 8, 2018, 7:06am UTC](https://forum.xojo.com/t/pi-execute-python-script-from-shell/42383 "2018-03-08T07:06:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dan\_Haglin](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/2bfe46/32.png) [@Dan\_Haglin](https://forum.xojo.com/u/Dan_Haglin)\
**Post date:** [March 8, 2018, 7:06am UTC](https://forum.xojo.com/t/pi-execute-python-script-from-shell/42383/1 "2018-03-08T07:06:48Z")

</div>

Trying to execute a python script from a shell and keep ending up with errors:  
Exception NilObjectException  
self MyWindow.MyWindow  
shell1 Nil

`Dim shell1 As Shell
'shell1.Execute("python /home/pi/Desktop/Upload.py aa bb cc")
`  
The aa bb and cc are separated with a space and are the three variables I am trying to pass to the python script.  
I have captured the command in a msgBox and pasted to the Terminal and it runs fine so there is something in the format of the shell that isn’t working. The python script is very basic and it works.  
Pasting the results of this message box into the Terminal works:

```auto
msgBox("python /home/pi/Desktop/Upload.py aa bb cc")
```

I have messed around with "\ " in the spaces from this thread but with no success.  
[link text](https://forum.xojo.com/40948-passing-arguments-to-python-script)

Any help would again be appreciated.

---

<div class="post-metadata">

**Author:** ![Beatrix\_Willius](https://forum.xojo.com/user_avatar/forum.xojo.com/beatrix_willius/32/282_2.png) [@Beatrix\_Willius](https://forum.xojo.com/u/Beatrix_Willius)\
**Post date:** [March 8, 2018, 8:38am UTC](https://forum.xojo.com/t/pi-execute-python-script-from-shell/42383/2 "2018-03-08T08:38:35Z")

</div>

```auto
dim theShell as new Shell
```

---

<div class="post-metadata">

**Author:** ![Greg\_O\_Lone](https://forum.xojo.com/user_avatar/forum.xojo.com/greg_o_lone/32/49_2.png) [@Greg\_O\_Lone](https://forum.xojo.com/u/Greg_O_Lone)\
**Post date:** [March 8, 2018, 12:30pm UTC](https://forum.xojo.com/t/pi-execute-python-script-from-shell/42383/3 "2018-03-08T12:30:15Z")

</div>

Beatrix is correct, but you will also probably need an absolute path for python in your command. Shell is not initialized with the same PATH as a terminal environment would be.

---

<div class="post-metadata">

**Author:** ![Dan\_Haglin](https://forum.xojo.com/letter_avatar_proxy/v4/letter/d/2bfe46/32.png) [@Dan\_Haglin](https://forum.xojo.com/u/Dan_Haglin)\
**Post date:** [March 8, 2018, 2:56pm UTC](https://forum.xojo.com/t/pi-execute-python-script-from-shell/42383/4 "2018-03-08T14:56:20Z")

</div>

_forehead slap_ Thank you Beatrix, can’t believe I missed that. That removed the error.  
Thank you Greg, I added an absolute path to python and now the script works as intended.

`Dim shell1 As New Shell
shell1.Execute("/usr/bin/python2.7 /home/pi/Desktop/Upload.py aa bb cc")`

---

<div class="post-metadata">

**Author:** ![system](https://forum.xojo.com/uploads/default/original/1X/455b4dcc0e61630e9f81940004ddffa49c432a46.png) [@system](https://forum.xojo.com/u/system)\
**Post date:** [October 29, 2020, 7:07pm UTC](https://forum.xojo.com/t/pi-execute-python-script-from-shell/42383/5 "2020-10-29T19:07:33Z")

</div>


