Get system command output: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (Fix Perl 6 -> Raku links) |
(→{{header|Tcl}}: + standard ml) |
||
Line 1,119: | Line 1,119: | ||
print(output!)</lang> |
print(output!)</lang> |
||
=={{header|Standard ML}}== |
|||
<lang Standard ML>val useOS = fn input => |
|||
let |
|||
val text = String.translate (fn #"\"" => "\\\""|n=>str n ) input ; |
|||
val shellCommand = " echo " ^ text ^ "| gzip -c " ; |
|||
val fname = "/tmp/fConv" ^ (String.extract (Time.toString (Posix.ProcEnv.time()),7,NONE) ); |
|||
val me = ( Posix.FileSys.mkfifo |
|||
(fname, |
|||
Posix.FileSys.S.flags [ Posix.FileSys.S.irusr,Posix.FileSys.S.iwusr ] |
|||
) ; |
|||
Posix.Process.fork () |
|||
) ; |
|||
in |
|||
if (Option.isSome me) then |
|||
let |
|||
val fin =BinIO.openIn fname |
|||
in |
|||
( Posix.Process.sleep (Time.fromReal 0.1) ; |
|||
BinIO.inputAll fin before |
|||
(BinIO.closeIn fin ; OS.FileSys.remove fname ) |
|||
) |
|||
end |
|||
else |
|||
( OS.Process.system ( shellCommand ^ " > " ^ fname ^ " 2>&1 " ) ; |
|||
Word8Vector.fromList [] before OS.Process.exit OS.Process.success |
|||
) |
|||
end; |
|||
</lang> |
|||
call |
|||
useOS "This is my text, zip it now" ; |
|||
val it = |
|||
fromList[0wx1F, 0wx8B, 0wx8, 0wx0, 0wxBE, 0wxCE, 0wx7F, 0wx5E, 0wx0, 0wx3, |
|||
...]: BinIO.vector |
|||
=={{header|Tcl}}== |
=={{header|Tcl}}== |