# Standard input and output can be handled through streams.
module exec
-import stream
+import file
# Simple sub-process
class Process
var arguments: nullable Array[String]
# Launch a command with some arguments
- init(command: String, arguments: String...)
- do
+ init(command: String, arguments: String...) is old_style_init do
self.command = command
self.arguments = arguments
execute
private fun basic_exec_execute(p: NativeString, av: NativeString, ac: Int, pf: Int): NativeProcess is extern "exec_Process_Process_basic_exec_execute_4"
end
-# stdout of the process is readable
-class IProcess
+# `Process` on which the `stdout` is readable like a `Reader`
+class ProcessReader
super Process
- super IStream
+ super Reader
# File Descriptor used for the input.
- var stream_in: FDIStream is noinit
+ var stream_in: FileReader is noinit
redef fun close do stream_in.close
redef fun read_char do return stream_in.read_char
+ redef fun read_byte do return stream_in.read_byte
+
redef fun eof do return stream_in.eof
redef fun pipeflags do return 2
redef fun execute
do
super
- stream_in = new FDIStream(data.out_fd)
+ stream_in = new FileReader.from_fd(data.out_fd)
end
end
-# stdin of the process is writable
-class OProcess
+# `Process` on which `stdin` is writable like a `Writer`
+class ProcessWriter
super Process
- super OStream
+ super Writer
# File Descriptor used for the output.
- var stream_out: OStream is noinit
+ var stream_out: Writer is noinit
redef fun close do stream_out.close
redef fun execute
do
super
- stream_out = new FDOStream(data.in_fd)
+ var out = new FileWriter.from_fd(data.in_fd)
+ out.set_buffering_mode(0, sys.buffer_mode_none)
+ stream_out = out
end
end
-# stdin and stdout are both accessible
-class IOProcess
- super IProcess
- super OProcess
- super IOStream
+# `Process` on which stdout can be read and stdin can be written to like a `Duplex`
+class ProcessDuplex
+ super ProcessReader
+ super ProcessWriter
+ super Duplex
redef fun close
do