Javascript 似乎无法将client.shell()命令的输出保存到变量

Javascript 似乎无法将client.shell()命令的输出保存到变量,javascript,node.js,adb,node-webkit,node-modules,Javascript,Node.js,Adb,Node Webkit,Node Modules,我正在使用node webkit和ADBkit尝试从android build.prop读取一行代码,并根据该行代码做一些事情 全文 其要点如下: var model = client.shell(devices, "su -c 'grep ro.product.model /system/build.prop'" ); alert(model) 我想将build.prop中的ro.product.model读入变量模型 作为一个测试,我只是试图创建一个显示此shell命令返回的警报,在我

我正在使用node webkit和ADBkit尝试从android build.prop读取一行代码,并根据该行代码做一些事情

全文

其要点如下:

var model = client.shell(devices, "su -c 'grep ro.product.model /system/build.prop'" );  
alert(model)
我想将build.prop中的ro.product.model读入变量模型 作为一个测试,我只是试图创建一个显示此shell命令返回的警报,在我的例子中是ro.product.model=KFSOWI,但每当我使用连接的设备运行此脚本时,警报都会返回对象

编辑** 我刚刚意识到client.getPropertieseSerial[,callback]可能工作得更好,但我不太理解这些函数


我对Javascripting这个领域非常陌生,有人可以提供一些见解,JavaScript是异步编程语言,它是建立在回调之上的。每个函数都应该有一个回调函数,其中包含传递给它的数据,如果您要监视,那么就有client.shellserial,command[,callback],所以执行client.shell的数据将传递给回调函数。您应该分配一些函数来处理回调,因为您的情况就是这样

client.shell(devices, "su -c 'grep ro.product.model /system/build.prop'", function(data) {
    console.log(data);
});

注意:nodejs中没有警报根据文档,您可以在client.shell回调的第二个参数中捕获输出:

client.shell(devices, "su -c 'grep ro.product.model /system/build.prop'", function(err, output) {
  if (err) {
    console.log(err);
  }
  console.log(output);
});
使用async/await获得更清晰的代码。 当然,这只在该代码位于异步函数中时才起作用

流数据。 对于使用adbkit的流式数据,您需要执行更多操作来读取整个流,然后输出结果,如下所示:

const stream = await adbClient.shell( config.udid, "ime list -s" ) // adb command to list possible input devices (e.g. keyboards, etc.).
const result = await adb.util.readAll( stream );
console.log( result.toString() ); // => com.sec.android.inputmethod/.SamsungKeypad
const stream = await adbClient.shell( config.udid, "ime list -s" ) // adb command to list possible input devices (e.g. keyboards, etc.).
const result = await adb.util.readAll( stream );
console.log( result.toString() ); // => com.sec.android.inputmethod/.SamsungKeypad