gnome-shell span_command_line_sync command is giving numerical values instead of text

45 views Asked by At

when I run the command uname-r in gnome-terminal. I get the result as 6.6.1-arch-1.

$ uname -r
6.6.1-arch1-1
$

I have created a gnome-shell-extension inside which I am calling the command below

const obj = GLib.spawn_command_line_sync('uname -r');
Main.notify('', JSON.stringify(obj)); // testing purpose
const kernelText = `Kernel Version ${obj[1].toString().trim()}`;

The obj I am getting is like this

enter image description here

How can I get the text with out this line,

const kernelText = `Kernel Version ${obj[1].toString().trim()}`;
1

There are 1 answers

0
andy.holmes On BEST ANSWER

GLib.spawn_command_line_sync() returns an array of four values: a success boolean, stdout as a Uint8Array, stderr as a Uint8Array and the wait status as a Number.

There is a guide for Spawning Subprocesses in GJS, or you may want to use GLib.get_os_info() if you're using it to spawn uname.

Spawning a synchronous subprocess in an extension is highly discouraged and will probably not pass review.