Skip to content

Conversation

@madhurig
Copy link
Contributor

We want to be able to write the output of the first tool to a file in addition to piping it to another tool to simulate something like this: xcodebuild | tee xcodebuild.log | xcpretty. This works but looking for feedback on the approach before adding unit tests.

this.pipeOutputToTool._getSpawnArgs(options),
this.pipeOutputToTool._getSpawnOptions(options));

let fileStream: fs.WriteStream = this.pipeOutputToFile ? fs.createWriteStream(this.pipeOutputToFile) : null;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will this work if the file already exists? It should append in that case I guess?


let fileStream: fs.WriteStream = this.pipeOutputToFile ? fs.createWriteStream(this.pipeOutputToFile) : null;
if (fileStream) {
fileStream.write(this._getCommandString(options) + os.EOL);
Copy link
Contributor

@ericsciple ericsciple Mar 22, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it weird to write the command string? I would expect the file to only contain the output of the first tool.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The command string helps set context for what this output was for. Otherwise user has to use the step number to match the output especially if there are multiple tasks of the same type that are producing these files. I initially did not write it but after I tried e2e it made more sense to write it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we cant do this. it may contain secrets and does not get run through the log scrubber

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good point!

cpFirst.stdout.on('data', (data: Buffer) => {
try {
if (fileStream) {
fileStream.write(data.toString());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why .toString()?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's right, it should not be needed. I will pull it out and verify.

});
cpFirst.stderr.on('data', (data: Buffer) => {
if (fileStream) {
fileStream.write(data.toString());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same question about .toString()

});
cpFirst.on('error', (err) => {
if (fileStream) {
fileStream.on('finish', () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

copy paste error? shouldn't this write stderr to the file too?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops I misread this.

defer.reject(new Error(toolPathFirst + ' failed. ' + err.message));
});
cpFirst.on('close', (code, signal) => {
if (fileStream) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if this is reliable. Do you know whether close means no further stdout/stderr data events are pending to be drained? I believe the node docs have good details about this, but I don't remember the details offhand.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should be as per https://nodejs.org/api/child_process.html#child_process_event_close - The 'close' event is emitted when the stdio streams of a child process have been closed. This is distinct from the 'exit' event, since multiple processes might share the same stdio streams.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wrote tests and found that there were some timing issues. I fixed the issues but the code looks ugly. Will sync up before doing any refactoring.

@madhurig madhurig force-pushed the users/madhurig/pipeToFileAndTool branch from 68e56e7 to 4c75ff7 Compare March 23, 2018 17:17

var inQuotes = false;
var escaped =false;
var escaped = false;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ericsciple: I ran format command in VSCode that brought in other changes. If you don't want these committed, I can back them out .

@madhurig madhurig merged commit f22b24b into master Mar 27, 2018
@madhurig madhurig deleted the users/madhurig/pipeToFileAndTool branch March 27, 2018 15:01
fullstackinfo pushed a commit to fullstackinfo/azure-pipelines-task-lib that referenced this pull request Aug 17, 2024
…FileAndTool

Add option to pipe to file and another tool
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants