title: Lua os.execute() does not work
body: <p>I'm having a problem with the Lua os.execute() command.</p>
  
  <p>I just want to echo a word and write it into a file, like <code>echo 'aword' &gt; C:\folder\tempworkspace\foo</code> to try the os.execute() command. The direcory C:\folder\tempworkspace exists, "foo" is the name of the file I want the command to create and fill with "aword".
  Later, when this works, I'd like to call R, using <code>R -q -e "rbinom(1000,1,0.7)" &gt; C:\folder\tempworkspace\foo</code>.</p>
  
  <p>I've already tried all the advice provided in
  <a href="https://stackoverflow.com/questions/5007266/lua-programming-os-execute-is-not-working-in-windows">Lua programming - os.execute() is not working in Windows</a> and <a href="https://stackoverflow.com/questions/3587788/why-wont-applications-in-program-files-run-using-os-execute-in-lua">Why won&#39;t applications in Program Files run using os.execute in lua?</a>
  but my problem seems to be a different one, maybe not even in the syntax, but somewhere else?</p>
  
  <p>When I type those command directly in the Command Prompt, they work. I use Windows 7 Professional as an administrator, and Lua 5.1.4 with Eclipse.</p>
  
  <p>Here is what I have tried so far:</p>
  
  <pre><code>os.execute("echo 'hehe' &gt; C:\folder\tempworkspace\foo")
  os.execute [["echo 'hehe' &gt; C:\folder\tempworkspace\foo"]]
  os.execute [["echo 'hehe' &gt; 'C:\folder\tempworkspace\foo'"]]
  os.execute [[echo 'hehe' &gt; C:\folder\tempworkspace\foo]]
  os.execute [[echo 'hehe' &gt; C:\\folder\\tempworkspace\\foo]]
  os.execute[[cmd.exe /c echo 'hehe' &gt; C:\folder\tempworkspace\foo]]
  os.execute("cmd.exe /c echo 'hehe' &gt; C:\\folder\\tempworkspace\\foo")
  os.execute("cmd.exe /c echo 'hehe' &gt; 'C:\\folder\\tempworkspace\\foo'")
  </code></pre>
  
  <p>I'd be very grateful for any suggestions to improve my code. (Note: I'm writing to a file, because I want to use the output later in lua. Another way of doing this, using io.popen() has been suggested somewhere, but it is said to be platform dependent, anyway my Lua crashes when I try to use <code>x = io.popen("R -q -e 'rnorm(10)'")</code>).</p>
  
  <p>Edit, after first answer:</p>
  
  <p>Your sendMsg function somehow also does not work on my computer, and I don't get any error, I really wonder what's the problem. For pcall, am I doing this right? As the line <code>print(err)</code> does not print anything I wonder if I am doing correctly.</p>
  
  <pre><code>function sendMsg(cmd, msg, fpath)
    local output = cmd.. " ".. msg.. " &gt; ".. fpath
    print(output)
    os.execute(output)
  end
  function sendMsgArgs()
    sendMsg("echo", "huhu", "C:\\merret\\tempworkspace\\foo");
  end
  err = pcall(sendMsgArgs) 
  if err == true then
    print("THIS WORKED")
  else
    print("THIS DID NOT WORK")
    print(err)
  end
  </code></pre>
  
  <p>Edit: This was actually a Eclipse/editor issue. So I wanted to add some tags, such as lua-eclipse, but I can't.</p>