3

I've seen Executing a shell command from Common Lisp and its answers, but I'm still not sure whether SBCL provides a way execute shell commands from code.

The SBCL Manual does support POSIX, but I was hoping for something a bit more higher level. Specifically, I want to call a Python script and capture the return value. Is there any way to do this?

Community
  • 1
  • 1
myselfesteem
  • 733
  • 1
  • 6
  • 23

1 Answers1

4

Given the file test.py:

import sys
sys.exit(42)

You can run it with sb-ext:run-program and examine the exit code as follows:

CL-USER> (sb-ext:run-program "python" '("test.py") :search t :wait t)
#<SB-IMPL::PROCESS :EXITED 42>
CL-USER> (sb-ext:process-exit-code *)
42
Joshua Taylor
  • 84,998
  • 9
  • 154
  • 353
jlahd
  • 6,257
  • 1
  • 15
  • 21