src/Pure/ML-Systems/smlnj.ML
changeset 26220 d34b68c21f9a
parent 26084 a7475459c740
child 26385 ae7564661e76
equal deleted inserted replaced
26219:2d026932f710 26220:d34b68c21f9a
     7 use "ML-Systems/proper_int.ML";
     7 use "ML-Systems/proper_int.ML";
     8 use "ML-Systems/overloading_smlnj.ML";
     8 use "ML-Systems/overloading_smlnj.ML";
     9 use "ML-Systems/exn.ML";
     9 use "ML-Systems/exn.ML";
    10 use "ML-Systems/universal.ML";
    10 use "ML-Systems/universal.ML";
    11 use "ML-Systems/multithreading.ML";
    11 use "ML-Systems/multithreading.ML";
       
    12 use "ML-Systems/system_shell.ML";
    12 
    13 
    13 
    14 
    14 (*low-level pointer equality*)
    15 (*low-level pointer equality*)
    15 
    16 
    16 CM.autoload "$smlnj/init/init.cmi";
    17 CM.autoload "$smlnj/init/init.cmi";
   227 val pwd = OS.FileSys.getDir;
   228 val pwd = OS.FileSys.getDir;
   228 
   229 
   229 
   230 
   230 (* system command execution *)
   231 (* system command execution *)
   231 
   232 
   232 (*execute Unix command which doesn't take any input from stdin and
   233 val system_out = (fn (output, rc) => (output, mk_int rc)) o system_out;
   233   sends its output to stdout; could be done more easily by Unix.execute,
       
   234   but that function doesn't use the PATH*)
       
   235 fun execute command =
       
   236   let
       
   237     val tmp_name = OS.FileSys.tmpName ();
       
   238     val is = (OS.Process.system (command ^ " > " ^ tmp_name); TextIO.openIn tmp_name);
       
   239     val result = TextIO.inputAll is;
       
   240   in
       
   241     TextIO.closeIn is;
       
   242     OS.FileSys.remove tmp_name;
       
   243     result
       
   244   end;
       
   245 
       
   246 (*plain version; with return code*)
       
   247 val system = mk_int o OS.Process.system;
       
   248 
   234 
   249 
   235 
   250 (*Convert a process ID to a decimal string (chiefly for tracing)*)
   236 (*Convert a process ID to a decimal string (chiefly for tracing)*)
   251 fun string_of_pid pid =
   237 fun string_of_pid pid =
   252     Word.fmt StringCvt.DEC (Word.fromLargeWord (Posix.Process.pidToWord pid));
   238   Word.fmt StringCvt.DEC (Word.fromLargeWord (Posix.Process.pidToWord pid));
   253 
   239 
   254 
   240 
   255 (* getenv *)
   241 (* getenv *)
   256 
   242 
   257 fun getenv var =
   243 fun getenv var =