How do I call out to a command-line program from a gnome shell extension?

不羁的心 提交于 2019-12-05 21:36:47

问题


I have written a simple shell script to accomplish a common task, and I want to be able to run it whenever a button is clicked. I've used gnome-shell-extension-tool to create the Hello World example already, but now I need to know how to simply have it run an arbitrary command when clicked. There is no input or output to be concerned with; it just needs to run.


回答1:


After some more creative googling, I've found the solution:

const Util = imports.misc.util;
Util.spawn(['/path/to/program', 'arg1', 'arg2'])



回答2:


const GLib = imports.gi.GLib;
let stuff = GLib.spawn_command_line_sync("cat hello.txt")[1].toString();

For those looking to read the output of the command, use this. The default working directory for Gnome shell extensions is the user's home directory.

Just thought I'd mention these things, because it took me a while to figure them out.



来源:https://stackoverflow.com/questions/17333982/how-do-i-call-out-to-a-command-line-program-from-a-gnome-shell-extension

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!