Home > Software design >  How can I do an unbuffered / live replacement in Powershells's output?
How can I do an unbuffered / live replacement in Powershells's output?

Time:10-26

I am trying to use powershell to absolutify relative paths in my CMake build output like this:

PS (./cmake.cmd rebuild) -replace '^(../) ','C:/my/absolut/path/prefix'

The cmake.cmd script is just a wrapper that eventually calls CMake with some options. The replacement itself works fine. However, the real build output appears only after the whole build process has been finished. Especially for a rebuild, this might take some time where there is not output on the console.

Is there a way to do this replacement in an unbuffered way so that I can still see a "live" output on the console? Thanks!

CodePudding user response:

Use a pipeline:

./cmake.cmd rebuild | foreach { $_ -replace '^(../) ','C:/my/absolut/path/prefix' }
  • Related