title: How do I get Tcl's exec to run a command whose arguments have quoted strings with spaces?
body: <p>I want to use <code>pgrep</code> to find the pid of a process from its command-line. In the shell, this is done as so:</p>
  
  <pre><code>pgrep -u andrew -fx 'some_binary -c some_config.cfg'
  </code></pre>
  
  <p>But when I try this from Tcl, like this:</p>
  
  <pre><code>exec pgrep -u $user -fx $cmdLine
  </code></pre>
  
  <p>I get:</p>
  
  <blockquote>
    <p>pgrep: invalid option -- 'c'</p>
  </blockquote>
  
  <p>Which makes sense, because it's seeing this:</p>
  
  <pre><code>pgrep -u andrew -fx some_binary -c some_config.cfg
  </code></pre>
  
  <p>But it's the same when I add single quotes:</p>
  
  <pre><code>exec pgrep -u $user -fx '$cmdLine'
  </code></pre>
  
  <p>And that also makes sense, because single quotes aren't special to Tcl. I think it's consider <code>'some_binary</code> an argument, then the <code>-c</code>, then the <code>some_config.cfg'</code>.</p>
  
  <p>I've also tried:</p>
  
  <pre><code>exec pgrep -u $user -fx {$cmdLine}
  </code></pre>
  
  <p>and</p>
  
  <pre><code>set cmd "pgrep -u $user -fx '$cmdLine'"
  eval exec $cmd
  </code></pre>
  
  <p>to no avail.</p>
  
  <p>From my reading it seems the <code>{*}</code> feature in Tcl 8.5+ might help, but my company infrastructure runs Tcl 8.0.5.</p>