How do I launch SBCL (or arbitrary commands) using popen?

51 Views Asked by At

I'm prototyping a GUI in C, which will trigger functions in a backend written in Lisp. I'm sure there's a more advanced way to do this, but for testing purposes, I wish to execute Lisp commands using the SBCL compiler, launched via the popen function in C.

I followed the instructions on launching Linux commands from within C from this video: https://www.youtube.com/watch?v=3bAAYel7L9o

Yielding the code:

int outputter(void){
  FILE *output;
  char buffer[BUFFER];

  output = popen("sbcl", "r");
  if (output == NULL) {
    fputs("POPEN: Failed.\n", stderr);
  }
      else {
        int count = 0;
        while(fgets(buffer, BUFFER-1, output) != NULL) {
            printf("OUTPUT[%d]: %s", count, buffer);
            count ++;
  }
      }
                pclose(output);

  return 0;
}

But when I run this function, it tells me: "sh: line 1: sbcl: command not found".

Does anyone have any guidance on successfully running such functions? I have read this answer, which suggests that the issue may be to do with whether the shell function is built-in (e.g. ls, not sbcl) or not, but I couldn't determine a way forward from that answer.

Information:

  • OS: Fedora 38
  • Language: C
  • IDE: Gnome Builder
  • sh: GNU bash, version 5.2.15 release (x86_64-redhat-linux-gnu)

Command not found when using popen

0

There are 0 best solutions below