title: How to run a CMD on web assembly without a server
body: <p>I wanted to create a web assembly program that would enable me to execute bash commands and get output without contacting a server.</p>
  <p>I created some rust code and did a wasm-pack compiling but it gives this error</p>
  <blockquote>
  <p>RuntimeError: unreachable executed</p>
  </blockquote>
  <p>My code</p>
  <pre><code>use std::process::Output;
  use wasm_bindgen::prelude::*;
  use std::process::Command;
  
  #[wasm_bindgen]
  pub fn exec(code:&amp;str)-&gt;Vec&lt;u8&gt;{
      
      let output = if cfg!(target_os = &quot;windows&quot;) {
      Command::new(&quot;cmd&quot;)
              .args([&quot;/C&quot;, code])
              .output()
              .expect(&quot;failed to execute process&quot;)
      } else {
          Command::new(&quot;sh&quot;)
                  .arg(&quot;-c&quot;)
                  .arg(code)
                  .output()
                  .expect(&quot;failed to execute process&quot;)
  
      };
  
      output.stdout
  }
  </code></pre>
  <p>^^lib.rs (used wasm-pack)</p>
  <blockquote>
  <p>RuntimeError: unreachable executed</p>
  </blockquote>