Joachim Breitner Joachim Breitner - 1 year ago 115
Bash Question

Safe version of OS.Process.system

Standard ML provides a function

val system : string -> status

in the
which invokes the argument via the shell.

It is generally good practice to avoid the shell if one does not need its features, due to quoting complexity, security issues and whatnot. So most languages also provide a direct execution function.

I could not find something like that in Standard ML. I would expect it to have a type similar to

val system : string -> string list -> status

How do I call something not via the system shell?

Answer Source

If your application runs on some Unix flavor, you could use the optional Unix structure, implemented by SML/NJ (at least):

val proc : (TextIO.instream, TextIO.outstream) Unix.proc =
  Unix.execute ("/bin/ls", ["-l"]);
val inStream = Unix.textInstreamOf proc;
val output = TextIO.inputAll inStream;
TextIO.closeIn inStream;
Unix.reap proc;
print output;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download