# 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:** 1\
**Showing post:** 2

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

---

_[View the full topic](https://forum.inductiveautomation.com/t/call-external-py-script-from-button/98920)._
