Skip to content

azure-pipelines-task-lib unnecessarily injects diagnostics into output streams #1100

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
reillysiemens opened this issue Apr 8, 2025 · 0 comments

Comments

@reillysiemens
Copy link
Member

When attempting to use tl.execAsync to read the contents from a command's stdout I have encountered an issue where diagnostic information containing the command name and arguments are injected into the output stream.

This JavaScript below serves as a minimal reproduction of the issue.

const assert = require("node:assert");
const fs = require("node:fs");
const { readFile, writeFile } = require("node:fs/promises");
const tl = require("azure-pipelines-task-lib/task");

(async () => {
  // Write "Hello World!" to foo.txt.
  const fooContents = "Hello, World!";
  await writeFile("foo.txt", fooContents);

  // Create an optional write stream to bar.txt.
  const stream = fs.createWriteStream("bar.txt");
  const options = { outStream: stream };
  await tl.execAsync("cat", ["foo.txt"], options);

  // Read back the contents of bar.txt.
  const barContents = await readFile("bar.txt", "utf-8");

  // 💣💥 Boom! They aren't equal! bar.txt is prefixed with:
  // [command]/usr/bin/cat foo.txt
  assert.strictEqual(
    fooContents,
    barContents,
    `foo.txt: "${fooContents}" != bar.txt: "${barContents}"`,
  );
})();

I don't know whether there are contexts where it would make sense to have this output in the stream coming from the subprocess, so I'm not sure if this is intentional, but it seems like bug to me. I think that the following code is responsible for the issue.
 

if (!optionsNonNull.silent) {
optionsNonNull.outStream!.write(this._getCommandString(optionsNonNull) + os.EOL);
}

Unfortunately, if you try to suppress this output by setting silent: true in the options then the entire output is supressed, which is not desirable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant