title: How to compile and run C in sublime text 3?
body: <p>I would like to compile and run C program in sublime text 3 on ubuntu 14.04. Currently the program is being compiled with gcc using sublime text 3 executing a command (see below code), but I was wondering if it's possible to have the program execution output to appear on sublime text console as well.</p>
  
  <p>Here's what I currently have to compile C program with sublime text 3</p>
  
  <p><strong>c_compile.sublime-build</strong></p>
  
  <pre><code>{
  "cmd" : ["gcc", "$file_name", "-o", "${file_base_name}"],
  "selector" : "source.c",
  "shell":false,
  "working_dir" : "$file_path"
  }
  </code></pre>
  
  <p>I've tried adding <code>&amp;&amp; ./${file_base_name}</code> like this:</p>
  
  <pre><code>{
  "cmd" : ["gcc", "$file_name", "-o", "${file_base_name}","&amp;&amp;","./${file_base_name}"],
  "selector" : "source.c",
  "shell":false,
  "working_dir" : "$file_path"
  }
  </code></pre>
  
  <p>But it's giving me this error:</p>
  
  <pre><code>gcc: error: &amp;&amp;: No such file or directory
  [Finished in 0.0s with exit code 1]
  [cmd: ['gcc', 'Ex1-6.c', '-o', 'Ex1-6', '&amp;&amp;', './Ex1-6']]
  [dir: /home/admin/Desktop/C/book/chap1]
  [path: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games]
  </code></pre>
  
  <p>Here's my simple C program I'm working with:</p>
  
  <p><strong>Ex1-6.c</strong></p>
  
  <pre><code>#include &lt;stdio.h&gt;
  
  main(){
      printf("Hello world");
  }
  </code></pre>
  
  <p>I searched online for a solution but suggested answers either allows to compile only (This parts is already working for me), or does not work. Any idea how to fix this code in order to compile and run in sublime text 3 (If possible). Thank you</p>
  
  <p><strong>Edit #1 as suggested by  user2357112:</strong></p>
  
  <p>After changing <code>shell</code> to <code>true</code>:</p>
  
  <pre><code>{
  "cmd" : ["gcc", "$file_name", "-o", "${file_base_name}","&amp;&amp;","./${file_base_name}"],
  "selector" : "source.c",
  "shell":true,
  "working_dir" : "$file_path"
  }
  </code></pre>
  
  <p>That's what I get:</p>
  
  <pre><code>gcc: fatal error: no input files
  compilation terminated.
  [Finished in 0.0s with exit code 4]
  [cmd: ['gcc', 'Ex1-6.c', '-o', 'Ex1-6', '&amp;&amp;', './Ex1-6']]
  [dir: /home/admin/Desktop/C/book/chap1]
  [path: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games]
  </code></pre>
  
  <p><strong>Edit #2 as suggested by Eugene K:</strong></p>
  
  <p>I tried changing cmd to run the program only:</p>
  
  <pre><code>{
  "cmd" : ["./${file_base_name}"],
  "selector" : "source.c",
  "shell":false,
  "working_dir" : "$file_path"
  }
  </code></pre>
  
  <p>It runs successfully and prints the output on the console with some code:</p>
  
  <pre><code>Hello world
  [Finished in 0.0s with exit code 12]
  [cmd: ['./Ex1-6']]
  [dir: /home/amir/Desktop/C/book/chap1]
  [path: /usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games]
  </code></pre>
  
  <p>So far the cmd either compiles or runs but does not do both together, hope something can be done to make it compile and run with a single command.</p>