Giter Club home page Giter Club logo

Comments (7)

wll8 avatar wll8 commented on August 25, 2024

call 方法返回一个数组,第一项为代码是否运行错误,第二项为代码 return 的返回值。

示例:从命令行获取 git 版本。

var [err, gitStr]= await main.ws.call(`run`, [
`
  var prcs = process.popen("git -v") // 运行命令
  var text = prcs.readAll() // 读取命令所有输出
  return text // 把数据抛给 js
`])

console.log(gitStr) // git version 2.41.0.windows.1

图片:
image

通过自定义 msg 订阅,也可以实现获取代码中的返回值。

示例:动态获取命令行输出。

var msg = new window.main.Msg() // 创建一个消息实例
msg.on(`run_xxx`, (info) => { // 监听 run_xxx 发来的消息
  console.log(`info`, info)
})
await main.ws.call(`run`, [
  `
  var prcs = process.popen("ping 127.0.0.1")
  for( all,out,err in prcs.each() ){ // 动态读取命令输出
    G.rpcServer.publish("run_xxx", out, err) // 向 run_xxx 发送消息
  }
  `
])

图片:
image

from sys-shim.

JunwayGuo avatar JunwayGuo commented on August 25, 2024

感谢回复,按照示例的确可以拿到字返回的字符串。
但,当命令有误,或缺少环境变量,未能获取异常的回调

如在没有path变量时候,执行 adb version

控制台应返回

image

而process.popen返回的是 undefined

from sys-shim.

wll8 avatar wll8 commented on August 25, 2024

不客气,欢迎一起完善此项目。

  1. 如果你说的是 js 里接收到的,那么它的错误只有在 ws.run 里的 code 有错误才会返回错误。
  2. 如果你说的是 ws.run 里的代码里的 process.popen,那他没有 undefined,并且如果命令不存在,他的返回值为空(这是 aardio 的行为)
  3. 如果你希望以 cmd 的行为回显错误,例如adb 不是内部命令,可以使用 process.popen.cmd
await main.ws.call(`run`, [
`
  var prcs = process.popen.cmd("adb -v") // 运行命令
  var text = prcs.readAll() // 读取命令所有输出
  return text // 把数据抛给 js
`])

图片:
image

from sys-shim.

JunwayGuo avatar JunwayGuo commented on August 25, 2024

感谢回复,我的问题已解决。
作者加油,希望不要放弃,完善一下。
我和你的困境一样,尝试过无数种方法,现在无奈用electron,如果搞定跨平台,这就是神器。
如果有需要,愿意加入团队,贡献代码。

from sys-shim.

wll8 avatar wll8 commented on August 25, 2024

那可真是太需要了!因为想写一些小工具又不想装一堆环境,所以弄了这东西。目前自己的小工具已实现。所以后面有新的小工具需求时,才会去继续完善此仓库代码。如果可以:

  • 你有一个项目A,使用此工具来做(暂主要支持 win 平台),可以实现收益的话,我很乐意参与项目A的贡献。这样我能恰饭的同时,完善此工具的同时也在和你一起完善项目A。

  • 如果后期需要跨平台,在通用 api 的项目上,对接相应平台的 bin 文件即可。

from sys-shim.

JunwayGuo avatar JunwayGuo commented on August 25, 2024

了解。
我目前可盈利的项目都有跨平台的需求。只能继续用Electron。
我近期打算开发一个小众需求的工具,并开源,使用你的框架,希望能帮助你推广。

from sys-shim.

wll8 avatar wll8 commented on August 25, 2024

好。有需要的操作系统API告诉我,我来封装。

from sys-shim.

Related Issues (9)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.