Yggtk/src/utils.vala

38 lines
1.3 KiB
Vala

/**
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
namespace Yggtk.Utils {
public bool is_command_available (string command) {
try {
string cmd_stdout, cmd_stderr;
int cmd_status = -1;
Process.spawn_command_line_sync (@"which $command", out cmd_stdout, out cmd_stderr, out cmd_status);
if (cmd_status == 0 && cmd_stderr.length == 0 && cmd_stdout.length > 0) {
return true;
}
} catch (SpawnError e) {
return false;
}
return false;
}
public string mktempdir () throws SpawnError {
string temp_dir = null;
Process.spawn_command_line_sync ("mktemp -d", out temp_dir);
return temp_dir.strip ();
}
}