Skip to content

Instantly share code, notes, and snippets.

@iacore
Forked from sogaiu/main.c
Last active October 12, 2023 09:53
Show Gist options
  • Save iacore/6acbb2d98403e468c35dd835518b9be5 to your computer and use it in GitHub Desktop.
Save iacore/6acbb2d98403e468c35dd835518b9be5 to your computer and use it in GitHub Desktop.
sh/exec-slurp via janet_dostring (assuming spork is installed)
// build:
//
// gcc -O0 -g main.c -I$HOME/.local/include -L$HOME/.local/lib -ljanet
// run:
//
// export LD_LIBRARY_PATH=$HOME/.local/lib
// ./a.out
#include "janet.h"
#include <stdio.h>
int main() {
JanetTable *env;
janet_init();
env = janet_core_env(NULL);
Janet out;
int status =
janet_dostring(env,
"(import spork/sh) (sh/exec-slurp `uname`)",
"source", &out);
printf("result: %d\n", status);
printf("is string: %d\n", janet_checktype(out, JANET_STRING));
printf("is nil: %d\n", janet_checktype(out, JANET_NIL));
janet_deinit();
}
@bakpakin
Copy link

bakpakin commented Oct 12, 2023

Try adding janet_loop after the call to janet_dostring. the janet_do* functions do not enter the event loop

EDIT: My mistake, that support is added. however, the result that is returned is not useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment