title: Random linebreaks in PowerShell standard error output
body: <p>I want to convert many .iso files to .mp4 with HandBrake, so I am trying to use the command line interface. I would prefer to write my scripts for this in powershell instead of batch files. However, the standard error contains linebreaks at random location if I use powershell.</p>
  
  <p>For troubleshooting, I created a simplified script both in powershell and in batch. </p>
  
  <p>Powershell:</p>
  
  <pre><code>&amp; "$Env:ProgramFiles\HandBrake\HandBrakeCLI.exe" @(
      '--input', 'V:\',
      '--title', '1', '--chapter', '1',
      '--start-at', 'duration:110', '--stop-at', 'duration:15',
      '--output', 'pmovie.mp4',
      '--format', 'av_mp4'
      ) &gt; ".\pstd.txt" 2&gt; ".\perr.txt"
  </code></pre>
  
  <p>Batch file:</p>
  
  <pre><code>"%ProgramFiles%\HandBrake\HandBrakeCLI.exe" --input V:\ --title 1 --chapter 1 --start-at duration:110 --stop-at duration:15 --output ".\cmovie.mp4" --format av_mp4 &gt; ".\cstd.txt" 2&gt; ".\cerr.txt"
  </code></pre>
  
  <p>Both scripts create the same .mp4 file, the difference is only the standard error output they create:</p>
  
  <p>Powershell:</p>
  
  <pre><code>HandBrakeCLI.exe : [10:41:44] hb_init: starting libhb thread
  At C:\Test\phandbrake.ps1:1 char:2
  + &amp; &lt;&lt;&lt;&lt;  "$Env:ProgramFiles\HandBrake\HandBrakeCLI.exe" @(
      + CategoryInfo          : NotSpecified: ([10:41:44] hb_i...ng libhb thread 
     :String) [], RemoteException
      + FullyQualifiedErrorId : NativeCommandError
  
  [10:41:44] thread 541fc20 started ("libhb")
  HandBrake 1.1.2 (2018090500) - MinGW x86_64 - https://handbrake.fr
  8 CPUs detected
  
  O
  pening V:\...
  
  [10:41:44] CPU: Intel(R) Core(TM) i7-2600K CPU @ 3.40GHz
  
  [10:41:44]  - Intel microarchitecture Sandy Bridge
  [10:41:44]  - logical processor count: 8
  
  [10:41:44] Intel Quick Sync Video support: no
  
  [10:41:44] hb_scan: path=V:\, title_index=1
  
  src/libbluray/disc/disc.c:424: error opening file BDMV\index.bdmv
  
  src/libbluray/disc/disc.c:424: error opening file BDMV\BACKUP\index.bdmv
  
  [10:41:44] bd: not a bd - trying as a stream/file instead
  
  libdvdnav: Using dvdnav version 6.0.0
  
  l
  ibdvdnav: Unable to open device file V:\.
  libdvdnav: vm: dvd_read_name failed
  libdvdnav: DVD disk re
  ports i
  tself wi
  th Region mask 0x
  0000000
  0. Reg
  ions:
   1 2 3 4 5 
  6 7 8
  </code></pre>
  
  <p>Batch file:</p>
  
  <pre><code>[10:41:35] hb_init: starting libhb thread
  [10:41:35] thread 5a2cc30 started ("libhb")
  HandBrake 1.1.2 (2018090500) - MinGW x86_64 - https://handbrake.fr
  8 CPUs detected
  Opening V:\...
  [10:41:35] CPU: Intel(R) Core(TM) i7-2600K CPU @ 3.40GHz
  [10:41:35]  - Intel microarchitecture Sandy Bridge
  [10:41:35]  - logical processor count: 8
  [10:41:35] Intel Quick Sync Video support: no
  [10:41:35] hb_scan: path=V:\, title_index=1
  src/libbluray/disc/disc.c:424: error opening file BDMV\index.bdmv
  src/libbluray/disc/disc.c:424: error opening file BDMV\BACKUP\index.bdmv
  [10:41:35] bd: not a bd - trying as a stream/file instead
  libdvdnav: Using dvdnav version 6.0.0
  libdvdnav: Unable to open device file V:\.
  libdvdnav: vm: dvd_read_name failed
  libdvdnav: DVD disk reports itself with Region mask 0x00000000. Regions: 1 2 3 4 5 6 7 8
  
  libdvdread: Attempting to retrieve all CSS keys
  libdvdread: This can take a _long_ time, please be patient
  
  libdvdread: Get key for /VIDEO_TS/VIDEO_TS.VOB at 0x00000130
  libdvdread: Elapsed time 0
  </code></pre>
  
  <p>This bothers me because I would like to check these text files to be sure that there was no error during the encoding.</p>
  
  <p>I suppose this may be related to a lack of synchronization between threads that write to the same stream but I am not sure about it.</p>
  
  <p><strong>The question: What can I do to get the standard error output from PowerShell without these random line breaks?</strong></p>