# Running Other Script (Python or Javascript) from K6 Script

**URL:** <https://community.grafana.com/t/running-other-script-python-or-javascript-from-k6-script/120809>\
**Category:** Grafana k6\
**Tags:** xk6, plugins\
**Created:** [May 2, 2024, 5:16pm UTC](https://community.grafana.com/t/running-other-script-python-or-javascript-from-k6-script/120809 "2024-05-02T17:16:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mipeters](https://avatars.discourse-cdn.com/v4/letter/m/d2c977/32.png) [@mipeters](https://community.grafana.com/u/mipeters)\
**Post date:** [May 2, 2024, 5:16pm UTC](https://community.grafana.com/t/running-other-script-python-or-javascript-from-k6-script/120809/1 "2024-05-02T17:16:41Z")

</div>

Hello, I have a python script and a javascript script that build a flatbuffer and converts it to binary. I need to run one of these scripts from inside the k6 default function and use it’s output. For example, lets say I have a javascript script called “test.js” and it returns a value “123.” I need to be able to call that “test.js” from inside the K6 default function and be able use the “123” value and send it over a websocket. Is this possible?

---

<div class="post-metadata">

**Author:** ![bandorko](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/bandorko/32/38733_2.png) [@bandorko](https://community.grafana.com/u/bandorko)\
**Post date:** [May 2, 2024, 11:37pm UTC](https://community.grafana.com/t/running-other-script-python-or-javascript-from-k6-script/120809/2 "2024-05-02T23:37:21Z")

</div>

Hi @mipeters , welcome to the community forum!

You can run external programs with the [GitHub - grafana/xk6-exec: A k6 extension for running external commands.](https://github.com/grafana/xk6-exec) extension.

**hello.py** :

```auto
print("123")

```

**script.js** :

```auto
import exec from 'k6/x/exec';

export function setup(){
  console.log(exec.command("python3",["hello.py"]));
}

export default function () {
  console.log("iteration")
}

```

The output of the `./k6 run -i 10 script.js` command (where k6 is the custom k6 binary with xk6-exec built into) is:

```auto
          /\ |‾‾| /‾‾/ /‾‾/   
     /\ / \ | |/ / / /    
    / \/ \ | ( / ‾‾\  
   / \ | |\ \ | (‾) | 
  / __________\ |__ | \ __\ \_____ / .io

  execution: local
     script: script.js
     output: -

  scenarios: (100.00%) 1 scenario, 1 max VUs, 10m30s max duration (incl. graceful stop):
           * default: 10 iterations shared among 1 VUs (maxDuration: 10m0s, gracefulStop: 30s)

INFO[0000] 123 source=console
INFO[0000] iteration source=console
INFO[0000] iteration source=console
INFO[0000] iteration source=console
INFO[0000] iteration source=console
INFO[0000] iteration source=console
INFO[0000] iteration source=console
INFO[0000] iteration source=console
INFO[0000] iteration source=console
INFO[0000] iteration source=console
INFO[0000] iteration source=console

     █ setup

     data_received........: 0 B 0 B/s
     data_sent............: 0 B 0 B/s
     iteration_duration...: avg=1.43ms min=8.23µs med=8.87µs max=15.6ms p(90)=48.73µs p(95)=7.82ms
     iterations...........: 10 618.017599/s

running (00m00.0s), 0/1 VUs, 10 complete and 0 interrupted iterations
default ✓ [======================================] 1 VUs 00m00.0s/10m0s 10/10 shared iters

```

I hope it helps
