title: Get the own process pid from the command prompt in windows
body: <p>I'm trying to get the PID from command prompt of its own. But when using the below command i'm not getting the desired output always. Can you please point out what was the error in the below statement?</p>
  
  <pre><code>cmd.exe /c title="mycmd" &amp; tasklist /v /fo csv | findstr /i "mycmd" &amp; dir &amp; help
  </code></pre>
  
  <p><strong>Edit:</strong></p>
  
  <p>The below command working correctly. But when combine it with two more commands. It's not working.</p>
  
  <pre><code>cmd.exe /c title="mycmd" &amp; tasklist /v /fo csv | findstr /i "mycmd"
  </code></pre>
  
  <p><strong>Additional Info:</strong></p>
  
  <p>I'm using Java</p>
  
  <pre><code>final List&lt;String&gt; commands = new ArrayList&lt;String&gt;();                
  
  commands.add("cmd.exe");
  commands.add("/C");
  
  //.. Add more commands
  
  ProcessBuilder pb = new ProcessBuilder(commands);
  </code></pre>