【发布时间】:2017-11-22 07:29:37
【问题描述】:
我正在为 Cinnamon GTK (Javascript) 编写一个小程序。
经过数小时的研究和反复试验,我终于设法生成了一个命令。但我不认为它有效地工作。许多页面返回 404,一些页面谈论食物香料,一些页面谈论其他语言的小程序......
无论如何,我的意思是文档很吓人。
使用Util(来自/usr/share/cinnamon/js/util.js),尝试:
Util.spawn_async(['/bin/bash', '-c', comm], CommandOutput);
我可以使用“CommandOutput(result)”函数获得输出。 现在我有了另一种方法:
let [res, pid, in_fd, out_fd, err_fd] = GLib.spawn_async_with_pipes(null, ["/usr/bin/command-name", "command-args"], null, GLib.SpawnFlags.SEARCH_PATH, null);
out_reader = new Gio.DataInputStream({base_stream: new Gio.UnixInputStream({fd: out_fd})});
let [out, size] = out_reader.read_line(null);
这似乎有效......
请告诉我对命令输出执行字符串函数的最佳方式?
有参考手册吗?最好的搜索词组是什么(在谷歌等)?
附:我还想将命令的输出写入临时文件。我该怎么做?
【问题讨论】:
标签: javascript applet command output cinnamon