Open yongrenjie opened 3 years ago
Generally there are three methods which could conceivably be used to run code with an external process, illustrated here with a shell script:
echo 'my_code' | sh
sh -c 'my_code'
sh my_code.sh
In theory we should deal with all three, but the pipes are the easiest to implement (using subprocess.Popen.communicate()
). 45fcf4a allows execution of Haskell code by piping it into runghc
.
.. exec::
:process: haskell
main :: IO ()
main = print $ take 20 fibs
where
fibs = 0 : scanl (+) 1 fibs
It would of course be nice to be able to completely customise this using the options, but I'm willing to settle for a bunch of predefined languages.
34d6829 allows execution of Matlab code via a tempfile.
7d67b77 allows shell scripts...
It seems easy enough to pass the code to stdin of a process.
Haskell would be a tougher one because ghc doesn't accept code passed via stdin. Probably the easiest way would be to make a tempfile, call ghc on that file and capture the stdout.