I’m writing a CLI program that makes service requests, transform data, and print letters to printer.
My plan is to consume Foxit Reader CLI tool in my Purescript but I’m not sure how to execute *.exe applications and pass arguments.
For this kind of work you’re going to want to use libraries from the purescript-node organization. Then you can search for Node solutions to your problems, and then use the relevant binding.
For example, in this case I think you’ll want to use exec
or execFile
to execute a *.exe application and pass arguments. That’s part of the child process API in Node, which is supplied in PureScript by the node-child-process library:
I did a quick search for how to do this in Node and found this answer:
which could be easily converted to use the PureScript Node bindings.
Since this thread lacks a working example, here’s a minimal code. For this to work you need to add dependencies "node-buffer", "node-child-process",
into your spago.dhall
file.
This code executes shell command echo
, then retrieves its stdout and prints via the standard log
function. Not very useful on its own, but hopefully pretty demonstrative.
module Main where
import Prelude
import Effect (Effect)
import Effect.Console (log)
import Node.Buffer as NodeBuf
import Node.ChildProcess as Exec
import Node.Encoding (Encoding(..))
main :: Effect Unit
main = do
stdout <- Exec.execSync "echo hello"
log =<< NodeBuf.toString UTF8 stdout