Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions dsc/src/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ use schemars::{Schema, schema_for};
use serde::Deserialize;
use std::collections::HashMap;
use std::env;
use std::io::{IsTerminal, Read};
use std::io::{IsTerminal, Read, stdout, Write};
use std::path::Path;
use std::process::exit;
use syntect::{
Expand Down Expand Up @@ -293,7 +293,11 @@ pub fn write_object(json: &str, format: Option<&OutputFormat>, include_separator
}
}
else {
println!("{output}");
let mut stdout_lock = stdout().lock();
if writeln!(stdout_lock, "{output}").is_err() {
// likely caused by a broken pipe (e.g. 'head' command closed early)
exit(EXIT_SUCCESS);
}
}
}

Expand Down
5 changes: 5 additions & 0 deletions dsc/tests/dsc.exit_code.tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,9 @@ Describe 'exit code tests' {
$result.actualState.exitCode | Should -Be 0
$LASTEXITCODE | Should -Be 0
}
It 'Exiting early due to broken pipe is a success' {
$out = dsc resource list | Select-Object -First 1 | ConvertFrom-Json
$out.Count | Should -Be 1
$LASTEXITCODE | Should -Be 0
}
}