Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8795801
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T23:28:10+00:00 2026-06-13T23:28:10+00:00

I’m having a problem with the Lua os.execute() command. I just want to echo

  • 0

I’m having a problem with the Lua os.execute() command.

I just want to echo a word and write it into a file, like echo 'aword' > C:\folder\tempworkspace\foo 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 R -q -e "rbinom(1000,1,0.7)" > C:\folder\tempworkspace\foo.

I’ve already tried all the advice provided in
Lua programming – os.execute() is not working in Windows and Why won't applications in Program Files run using os.execute in lua?
but my problem seems to be a different one, maybe not even in the syntax, but somewhere else?

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.

Here is what I have tried so far:

os.execute("echo 'hehe' > C:\folder\tempworkspace\foo")
os.execute [["echo 'hehe' > C:\folder\tempworkspace\foo"]]
os.execute [["echo 'hehe' > 'C:\folder\tempworkspace\foo'"]]
os.execute [[echo 'hehe' > C:\folder\tempworkspace\foo]]
os.execute [[echo 'hehe' > C:\\folder\\tempworkspace\\foo]]
os.execute[[cmd.exe /c echo 'hehe' > C:\folder\tempworkspace\foo]]
os.execute("cmd.exe /c echo 'hehe' > C:\\folder\\tempworkspace\\foo")
os.execute("cmd.exe /c echo 'hehe' > 'C:\\folder\\tempworkspace\\foo'")

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 x = io.popen("R -q -e 'rnorm(10)'")).

Edit, after first answer:

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 print(err) does not print anything I wonder if I am doing correctly.

function sendMsg(cmd, msg, fpath)
  local output = cmd.. " ".. msg.. " > ".. 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

Edit: This was actually a Eclipse/editor issue. So I wanted to add some tags, such as lua-eclipse, but I can’t.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T23:28:11+00:00Added an answer on June 13, 2026 at 11:28 pm

    this snippet of code works on my Win7 box:

    function sendMsg(cmd, msg, fpath)
        local output = cmd.. " ".. msg.. " > ".. fpath
        print(output)
        os.execute(output)
    end
    
    sendMsg("echo", "hehe", "C:\\path\\to\\foo");
    

    you need to make sure the file exists before you attempt to write to it. are you running this from the lua interpreter? do you get any error messages back when it fails to do the write?

    alternatively – you can just use io.open() and write that way. wrapping this in a function and calling it using pcall() may give you more information if you have some sort of windows issue opening/reading to that location.

    local fout = io.open("C:\\path\\to\\foo", "w+")
    fout:write("hehe")
    fout:close()
    

    an example using pcall:

    local result, error = pcall(sendMsg, "echo", "huhu", "C:\\merret\\tempworkspace\\foo")
    if result == false then
        print(error)
    else
        print("success!")
    end 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I have just tried to save a simple *.rtf file with some websites and
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I am trying to render a haml file in a javascript response like so:
I am currently running into a problem where an element is coming back from
I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
i want to parse a xhtml file and display in UITableView. what is the
I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.