| 128 | //------------------------------------------------------------------------------------------------------- |
| 129 | SC::Process::Options::Options() |
| 130 | { |
| 131 | windowsHide = Process::isWindowsConsoleSubsystem(); |
| 132 | windowsCreateNewProcessGroup = false; |
| 133 | } |
| 134 | |
| 135 | SC::ResultProcess SC::Process::launch(const StdOut& stdOutput, const StdIn& stdInput, const StdErr& stdError) |
| 136 | { |
| 137 | auto setupInput = [](const StdIn& inputObject, PipeDescriptor& pipe, |
| 138 | FileDescriptor& fileDescriptor) -> ResultProcess |
| 139 | { |
| 140 | switch (inputObject.operation) |
| 141 | { |
| 142 | case StdStream::Operation::AlreadySetup: break; |
| 143 | case StdStream::Operation::Inherit: break; |
| 144 | case StdStream::Operation::Ignore: break; |
| 145 | case StdStream::Operation::FileDescriptor: { |
| 146 | if (not fileDescriptor.assign(inputObject.fileDescriptor)) |
| 147 | return ResultProcess(ProcessError::InvalidInputRedirection); |
| 148 | } |
| 149 | break; |
| 150 | case StdStream::Operation::ExternalPipe: { |
| 151 | if (not fileDescriptor.assign(move(inputObject.pipeDescriptor->readPipe))) |
| 152 | return ResultProcess(ProcessError::InvalidInputRedirection); |
| 153 | } |
| 154 | break; |
| 155 | case StdStream::Operation::GrowableBuffer: |
| 156 | case StdStream::Operation::ReadableSpan: { |
| 157 | PipeOptions pipeReadOptions; |
| 158 | pipeReadOptions.readInheritable = true; |
| 159 | pipeReadOptions.writeInheritable = false; |
| 160 | SC_TRY(pipe.createPipe(pipeReadOptions)); |
| 161 | SC_TRY(fileDescriptor.assign(move(pipe.readPipe))); |
| 162 | } |
| 163 | break; |
| 164 | case StdStream::Operation::WritableSpan: { |
| 165 | return ResultProcess(ProcessError::UnsupportedInputRedirection); |
| 166 | } |
| 167 | } |
| 168 | return ResultProcess(true); |
| 169 | }; |
| 170 | |
| 171 | auto setupOutput = [](const StdOut& outputObject, PipeDescriptor& pipe, |
| 172 | FileDescriptor& fileDescriptor) -> ResultProcess |
| 173 | { |
| 174 | switch (outputObject.operation) |
| 175 | { |
| 176 | case StdStream::Operation::AlreadySetup: break; |
| 177 | case StdStream::Operation::Inherit: break; |
| 178 | case StdStream::Operation::Ignore: { |
| 179 | SC_TRY(fileDescriptor.openForWriteToDevNull()); |
| 180 | break; |
| 181 | } |
| 182 | case StdStream::Operation::FileDescriptor: { |
| 183 | if (not fileDescriptor.assign(outputObject.fileDescriptor)) |
| 184 | return ResultProcess(ProcessError::InvalidOutputRedirection); |
| 185 | } |
| 186 | break; |
| 187 | case StdStream::Operation::ExternalPipe: { |
no test coverage detected