title: Windows cmd echo / pipe is adding extra space at the end - how to trim it?
body: <p>I'm working on a script that executes a command line application which requires user input at runtime (sadly command line arguments are not provided).</p>
  
  <p>So my first attempt looked like this:</p>
  
  <pre><code>@echo off
  (echo N
  echo %~dp0%SomeOther\Directory\
  echo Y)|call "%~dp0%SomeDirectory\SadSoftware.exe"
  </code></pre>
  
  <p>At first glance it looked like it worked pretty well, but as it turned out it didn't. After investigation I found out that the directory I was passing to the software contained extra space at the end, which resulted in some problems.</p>
  
  <p>I looked around for a while and found out following question:
  <a href="https://stackoverflow.com/questions/10948824/echo-is-adding-space-when-used-with-a-pipe">echo is adding space when used with a pipe</a> .</p>
  
  <p>This explained what is going on, but didn't really help me solve my problem (I'm not too familiar with batch programming).</p>
  
  <p>At the moment I "kind of solved" my problem with an ugly workaround:</p>
  
  <pre><code>echo N&gt; omg.txt
  echo %~dp0%SomeOther\Directory\&gt;&gt; omg.txt
  echo Y&gt;&gt; omg.txt
  
  "%~dp0%SomeDirectory\SadSoftware.exe"&lt;omg.txt
  
  del omg.txt
  </code></pre>
  
  <p>This solution works, but I'm less than happy with it. Is there some prettier way? Or even uglier way, but without temporary file?</p>