MCPcopy Create free account
hub / github.com/Pagghiu/SaneCppLibraries / processChainPipeDual

Method processChainPipeDual

Tests/Libraries/Process/ProcessTest.cpp:260–294  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

258}
259
260void SC::ProcessTest::processChainPipeDual()
261{
262 //! [processChainPipeDualSnippet]
263 // Chain two processes and read the last stdout into a String (using a pipe)
264 ProcessChain chain;
265
266 String output(StringEncoding::Ascii);
267 Process p1, p2;
268
269 StringView expectedOutput;
270 switch (HostPlatform)
271 {
272 case Platform::Windows: {
273 expectedOutput = "WHERE [/R dir] [/Q] [/F] [/T] pattern...\r\n";
274 SC_TEST_EXPECT(chain.pipe(p1, {"where", "/?"}));
275 SC_TEST_EXPECT(chain.pipe(p2, {"findstr", "dir]"}));
276 }
277 break;
278 default: { // Posix
279 expectedOutput = "sbin\n";
280 SC_TEST_EXPECT(chain.pipe(p1, {"ls", "/"}));
281 SC_TEST_EXPECT(chain.pipe(p2, {"grep", "sbin"}));
282 }
283 break;
284 }
285 PipeOptions pipeOptions;
286 pipeOptions.writeInheritable = true; // This is correct but not strictly necessary...
287 PipeDescriptor outputPipe;
288 SC_TEST_EXPECT(outputPipe.createPipe(pipeOptions));
289 SC_TEST_EXPECT(chain.launch(outputPipe));
290 SC_TEST_EXPECT(outputPipe.readPipe.readUntilEOF(output));
291 SC_TEST_EXPECT(chain.waitForExitSync());
292 SC_TEST_EXPECT(StringView(output.view()).startsWith(expectedOutput));
293 //! [processChainPipeDualSnippet]
294}
295
296// This section is not executed as a test, but explicitly executed in a child process by some tests below
297void SC::ProcessTest::processEnvironmentPrint()

Callers

nothing calls this directly

Calls 7

createPipeMethod · 0.80
readUntilEOFMethod · 0.80
waitForExitSyncMethod · 0.80
startsWithMethod · 0.80
pipeMethod · 0.45
launchMethod · 0.45
viewMethod · 0.45

Tested by

no test coverage detected