Инициализация 0.1.0
This commit is contained in:
commit
abdc9d4cce
10 changed files with 158 additions and 0 deletions
26
source/examples/shell/pipe.d
Normal file
26
source/examples/shell/pipe.d
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
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);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue