# Call external py script from button

**URL:** <https://forum.inductiveautomation.com/t/call-external-py-script-from-button/98920>\
**Category:** Ignition\
**Tags:** scripting\
**Created:** [November 21, 2024, 9:03am UTC](https://forum.inductiveautomation.com/t/call-external-py-script-from-button/98920 "2024-11-21T09:03:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hfj](https://avatars.discourse-cdn.com/v4/letter/h/c4cdca/32.png) [@hfj](https://forum.inductiveautomation.com/u/hfj)\
**Post date:** [November 21, 2024, 9:03am UTC](https://forum.inductiveautomation.com/t/call-external-py-script-from-button/98920/1 "2024-11-21T09:03:50Z")

</div>

I have a script that test a local ip for connected PLC unit info. I want to call this from a button i ignition.  
I am not sure where to put the script. On the button or in gateway scripts ?  
Also how to get the result show up in a textbox  
Here is my script:

```python
import subprocess

pythonPath = "C:/Program Files/Python313/python.exe"
scriptPath = "c:/Python/S7_Dev_Env/listOnlineDevice.py"
param1 = "5"

result = subprocess.check_output([pythonPath, scriptPath, param1])
print result

```

---

<div class="post-metadata">

**Author:** ![bkarabinchak.psi](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/bkarabinchak.psi/32/83567_2.png) [@bkarabinchak.psi](https://forum.inductiveautomation.com/u/bkarabinchak.psi)\
**Post date:** [November 21, 2024, 2:11pm UTC](https://forum.inductiveautomation.com/t/call-external-py-script-from-button/98920/2 "2024-11-21T14:11:10Z")

</div>

> [@hfj](#):
>
> I am not sure where to put the script. On the button or in gateway scripts ?

Where does the .py file live - on the client running vision, or on the gateway? If the client is running perspective, all scripts run on the gateway and it will need to be on the gateway.

You will want to use ProcessBuilder over subprocess. Check out this example though there are others here if you search

> [@Procedure for installing python libraries from source](https://forum.inductiveautomation.com/t/procedure-for-installing-python-libraries-from-source/26022/16):
>
> Oh, right - system.util.execute is a 'fire-and-forget', it doesn't give you access to standard output. Try adapting this: from java.lang import ProcessBuilder, String pb = ProcessBuilder([r"C:\Users\pgriffith\AppData\Local\Microsoft\WindowsApps\python3.exe", r"C:\Users\pgriffith\Downloads\test.py"]) process = pb.start() output = String(process.getInputStream().readAllBytes()) print output (Note: This blocks until the process completes waiting on the input stream. It may or may not ever compl…

Note too - if this is vision - it does likely make more sense to have it on the gateway instead of putting a .py file on every single client. You can then write the result to a gateway tag and bind the button text to that in some fashion, or use message handlers.
