question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Start-Process: Provide the ability to append when redirecting stdout/stderr streams to file

See original GitHub issue

Include an option/directive for the ‘Start-Process’ cmdlet that allows the user to specify that stream output should be *appended to an existing output file when redirecting the stdout/stderr streams to file.

Currently, when using either the ‘-RedirectStandardOutput’ or ‘-RedirectStandardError’ parameters to specify output file paths for redirection of the standard streams to file, the behavior of ‘Start-Process’ is to create/overwrite if a specified file exists. There is no means to have the output appended to an existing file. This forces the user to come up with additional and, IMHO, seemingly unnecessary work-arounds in order to implement the append logic. This seems like something that could be relatively easily implemented at a lower level, and, quite frankly, seems like basic functionality that the cmdlet should already support.

This could be as simple as adding some kind of append specifier to each parameter:

# stdout files gets overwritten (default behavior), stderr file gets appended to ('>>' specifier)
Start-Process -RedirectStandardOutput='logfile.txt' -RedirectStandardError='>>errlog.txt'

Of course, this could be setup in a variety of ways and/or as the powershell devs see fit.

Justification: There are a variety of cases where it would be useful to be able to have a complete output history of a child process’ output, even when the same child process is created multiple times, or across multiple executions of the parent script/command. Having the ability to append output files directly from ‘Start-Process’ would increase its usefulness in this respect.

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

3reactions
jborean93commented, Mar 16, 2021

Or maybe even a mode like -RedirectOutputMode Create/Append (same for Error). This could have the benefit of adding Store/Var support where -RedirectStandardOutput is the name of a variable to redirect the value to.

2reactions
iSazonovcommented, Mar 16, 2021

I don’t like an cryptic things in PowerShell language - it is hard for users to discover them. It is more preferable to have an additional switch or two with self described name(s) like -AppendToOutput/-AppendToError.

Read more comments on GitHub >

github_iconTop Results From Across the Web

of standard and error output appending to the same log file ...
In order to append to a file you'll need to use a slightly different approach. You can still redirect an individual process' standard...
Read more >
about Redirection - PowerShell
Redirects the specified stream to the Success stream. Unlike some Unix shells, you can only redirect other streams to the Success stream.
Read more >
How to Redirect Docker Logs to a Single File | Scalyr
Learn how to redirect docker logs to a single file! We look at how we can manipulate logs generated by the default json-file...
Read more >
How to keep the output order when redirecting both stdout ...
The default behaviour is that output to stdout is line buffered if it goes to a terminal, but fully buffered if it goes...
Read more >
Append both stdout and stderr to a file - bash
1 Answer 1 · Either use this construct: cmd >>file.txt 2>&1 where >> file appends the output to the file and 2>&1 redirects...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found