# Executing ADB commands from the script

**URL:** <https://discuss.appium.io/t/executing-adb-commands-from-the-script/36319>\
**Category:** Support\
**Created:** [May 10, 2022, 12:56pm UTC](https://discuss.appium.io/t/executing-adb-commands-from-the-script/36319 "2022-05-10T12:56:26Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Harsha](https://discuss.appium.io/user_avatar/discuss.appium.io/harsha/32/9397_2.png) [@Harsha](https://discuss.appium.io/u/Harsha)\
**Post date:** [May 10, 2022, 12:56pm UTC](https://discuss.appium.io/t/executing-adb-commands-from-the-script/36319/1 "2022-05-10T12:56:26Z")

</div>

Hi Team,

I want to execute **adb shell pm clear** \< **package-name** \> command in after() block of my script.

I tried 2 things:

1. Use below piece of code in after() block but it gave me error:

> await driver.executeScript(‘mobile: shell’, [{  
> command: ‘pm clear’,\*\*  
> args: [‘com.gelato.api.stage’],\*\*  
> }]);

> unknown error: An unknown server-side error occurred while processing the command. Original error: Potentially insecure feature ‘adb\_shell’ has not been enabled. If you want to enable this feature and accept the security ramifications, please do so by following the documented instructions at [https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/security.md](https://github.com/appium/appium/blob/master/docs/en/writing-running-appium/security.md)  
> at async Context. (/Users/harsha.sharma/Dev/work/sandbox/repo/integration-tests/src/specs/android/login.spec.ts:17:6)

To resolve this issue, I also tried to execute appium command in wdio.config by including below section of code in my _ **wdio.config** _ but this also did not solved my issue.

> appium: {  
> command: ‘appium --relaxed-security --allow-insecure=adb\_shell --chromedriver-executable /Users/harsha.sharmagelato.com/Dev/work/sandbox/gelato-api-mobile/integration-tests/node\_modules/appium-chromedriver/chromedriver/mac/chromedriver\_mac64\_v91.0.4472.101’,  
> // args: [‘–allow-insecure’, ‘chromedriver\_autodownload’],  
> },

1. Then I also tried after installing appium-adb, this also did not work for me.

Can someone please guide me how should I solve this issue?

Thanks 🙂

---

<div class="post-metadata">

**Author:** ![wreed](https://discuss.appium.io/letter_avatar_proxy/v4/letter/w/919ad9/32.png) [@wreed](https://discuss.appium.io/u/wreed)\
**Post date:** [May 10, 2022, 3:18pm UTC](https://discuss.appium.io/t/executing-adb-commands-from-the-script/36319/2 "2022-05-10T15:18:28Z")

</div>

Why not make a system call?

[https://www.codejava.net/java-se/file-io/execute-operating-system-commands-using-runtime-exec-methods](https://www.codejava.net/java-se/file-io/execute-operating-system-commands-using-runtime-exec-methods)

---

<div class="post-metadata">

**Author:** ![Harsha](https://discuss.appium.io/user_avatar/discuss.appium.io/harsha/32/9397_2.png) [@Harsha](https://discuss.appium.io/u/Harsha)\
**Post date:** [May 11, 2022, 9:20am UTC](https://discuss.appium.io/t/executing-adb-commands-from-the-script/36319/3 "2022-05-11T09:20:40Z")

</div>

I am not sure if it will be helpful in my case. My project is in TypeScript and I doubt if there is any system call through which I can logout my app after completing my testExecution.

I think it will be better either to use any ADB command or some appium webdriverIO function which will help me to accomplish this.  
What are your thoughts on this ?

---

<div class="post-metadata">

**Author:** ![wreed](https://discuss.appium.io/letter_avatar_proxy/v4/letter/w/919ad9/32.png) [@wreed](https://discuss.appium.io/u/wreed)\
**Post date:** [May 11, 2022, 3:43pm UTC](https://discuss.appium.io/t/executing-adb-commands-from-the-script/36319/4 "2022-05-11T15:43:09Z")

</div>

My thoughts are you know where the documentation is, knock yourself out. Keep in mind that you may find a system call is the best solution. It’s your project, so I encourage you to do it your way.
