node adb shell

var spawn = require('child_process').spawn;
const ls = spawn('adb', ['shell', '']);
var commands =["cd sdcard","cd libs","ls"]
ls.stdout.on('data', (data) => {
  console.log(`stdout: ${data}`);
  // if () {}
  if (commands.length > 0) {
  	ls.stdin.write(commands[0] + '\n');
     commands.shift()
  }
  
});


ls.stderr.on('data', (data) => {
  console.log(`stderr: ${data}`);
});

ls.on('close', (code) => {
  console.log(`子进程退出码:${code}`);
});

 

转载于:https://my.oschina.net/u/1474965/blog/1634789

好的,我来给您写一个用 TypeScript 实现的按钮,点击按钮后使用 `adb shell` 命令: ```typescript class AdbButton { private button: HTMLButtonElement; constructor() { this.button = document.createElement('button'); this.button.textContent = '执行 adb shell 命令'; this.button.addEventListener('click', () => this.executeAdbShellCommand()); document.body.appendChild(this.button); } private executeAdbShellCommand(): void { const command = 'adb shell <your command>'; // 请将 <your command> 替换为您要执行的命令 const process = Deno.run({ cmd: ['sh', '-c', command] }); process.status().then((status) => { if (status.success) { console.log('命令执行成功!'); } else { console.log('命令执行失败!'); } }); } } const adbButton = new AdbButton(); ``` 这个类的构造函数会创建一个按钮,并将按钮添加到页面中。当按钮被点击时,它会使用 `Deno.run` 函数执行一个基于 `adb shell` 命令的子进程。请将 `<your command>` 替换为您要执行的命令。 执行完命令后,程序会根据子进程的执行状态输出相应的提示信息。 请注意,由于 `Deno.run` 函数需要访问系统资源,因此需要在代码中声明访问权限。如果您使用浏览器环境,则需要在页面中添加以下标记: ```html <meta name="deno-permissions" content="allow-run" /> ``` 这将允许程序在浏览器中使用 `Deno.run` 函数。 如果您使用的是 Node.js 环境,则不需要添加此标记。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值