d-examples/source/examples/shell/pipe.d

26 lines
556 B
D
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

module examples.shell.pipe;
import std.process : pipeProcess, Redirect, wait;
import std.stdio : writeln;
void pipeShell()
{
try
{
// Выполняем команду ping с аргументами
auto pipes = pipeProcess(["ping", "8.8.8.8", "-c", "4"], Redirect.stdout);
// Читаем вывод команды построчно
foreach (line; pipes.stdout.byLine)
{
writeln(line);
}
// Ожидаем завершения процесса
wait(pipes.pid);
}
catch (Exception e)
{
writeln("Ошибка: ", e.msg);
}
}