# Run script on command-line

**URL:** <https://forum.qoitech.com/t/run-script-on-command-line/444>\
**Category:** Automation Toolbox\
**Created:** [August 25, 2022, 12:58pm UTC](https://forum.qoitech.com/t/run-script-on-command-line/444 "2022-08-25T12:58:44Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![solene](https://avatars.discourse-cdn.com/v4/letter/s/9f8e36/32.png) [@solene](https://forum.qoitech.com/u/solene)\
**Post date:** [August 25, 2022, 12:58pm UTC](https://forum.qoitech.com/t/run-script-on-command-line/444/1 "2022-08-25T12:58:44Z")

</div>

Hi, I am new on OTII Automation toolbox

I need to launch a python script without open manually OTII soft. For this :  
I open command-line and type : otiicli -s example\_basic\_function\_check.py’

 ![image](https://europe1.discourse-cdn.com/flex017/uploads/qoitech/original/1X/efa3ff3e23ef8008c1a9b13cd07b5cd98a6c931a.png)

And after that, I cannot write anything without quitting the server listening. So I can’t launch my script. This is the same reaction for ‘otiicli -s’  
I also tried ‘otiicli example\_basic\_function\_check.py’ but it doesn’t work without start server listening before.

Do you have some advice to help me ?  
Thanks !

---

<div class="post-metadata">

**Author:** ![solene](https://avatars.discourse-cdn.com/v4/letter/s/9f8e36/32.png) [@solene](https://forum.qoitech.com/u/solene)\
**Post date:** [August 26, 2022, 8:50am UTC](https://forum.qoitech.com/t/run-script-on-command-line/444/2 "2022-08-26T08:50:51Z")

</div>

Hi, problem solved

I didn’t see the following link : [Qoitech Documentation](https://www.qoitech.com/docs/advanced/scripting-with-python), it was very helpful. Thanks.

Just a comment in " Start otiicli from Script" chapter :  
I imported subprocess : `import subprocess`  
I pasted the following script part and changed my USERNAME and PASSWORD by mine:

```auto
cmd = f'otiicli --server --username={USERNAME} --password={PASSWORD}'
server = subprocess.Popen(cmd, shell=True)

```

Then, I used those lines :

```auto
connection = otii_connection.OtiiConnection(cfg.HOST["IP"], cfg.HOST["PORT"])
connect_response = connection.connect_to_server()
if connect_response["type"] == "error":
    print("Exit! Error code: " + connect_response["errorcode"] + ", Description: " + connect_response["data"]["message"])
    sys.exit()

```

It permits to make no change on Host IP and Port comparing to the given script.  
Maybe this will help someone !

---

<div class="post-metadata">

**Author:** ![solene](https://avatars.discourse-cdn.com/v4/letter/s/9f8e36/32.png) [@solene](https://forum.qoitech.com/u/solene)\
**Post date:** [August 26, 2022, 9:10am UTC](https://forum.qoitech.com/t/run-script-on-command-line/444/3 "2022-08-26T09:10:38Z")

</div>

I forgot :  
for the second lines, we must add : `import example_config as cfg`  
the example\_config.py script :

```auto
#!/usr/bin/env python
HOST = {
    # IP address of the server
    "IP":"127.0.0.1",
    # Port number the server is listening on
    "PORT":1905
    }

```

---

<div class="post-metadata">

**Author:** ![bjorn.rosqvist](https://dub1.discourse-cdn.com/flex017/user_avatar/forum.qoitech.com/bjorn.rosqvist/32/238_2.png) [@bjorn.rosqvist](https://forum.qoitech.com/u/bjorn.rosqvist)\
**Post date:** [August 29, 2022, 8:22am UTC](https://forum.qoitech.com/t/run-script-on-command-line/444/4 "2022-08-29T08:22:50Z")

</div>

Hi,

Thank you for posting this!

Best regards,  
Björn
