0

***************I have two script*************************

File name : abcd.py

def fun() :
    x = 1
    return x

z = fun()
print z

File name xyz.lua

os.execute('start cmd /c C:/Python34/python.exe "C:/Folder/abcd.py"')  

I am not getting result. Plesae help me on this, how can i execute a python script from lua. Here i want to run abcd.py script from xyz.lua

I am working in windows environment.

Snehasish
  • 11
  • 2
  • Does this answer your question? [Lua os.execute return value](https://stackoverflow.com/questions/9676113/lua-os-execute-return-value) – Maurice Meyer Jun 03 '20 at 06:30
  • `os.execute` provides return/status code only. – Maurice Meyer Jun 03 '20 at 06:32
  • Try `os.execute('start cmd /k C:/Python34/python.exe "C:/Folder/abcd.py"')` – Egor Skriptunoff Jun 03 '20 at 11:44
  • 1
    If `start` works, that means `os.execute` already uses the CMD shell. You don't need another instance. Using `start` will cause python.exe to allocate a new console. Without `/w`, the shell won't wait for python.exe to exit. If you don't need a new console, run `'"C:\\Python34\\python.exe" "C:/Folder/abcd.py"'`. If you need a new console plus the exit code, make it wait via `'start "" /w "C:\\Python34\\python.exe" "C:/Folder/abcd.py"'`. CMD needs backslashes for the python.exe path. Python accepts slashes for the "abcd.py" path. – Eryk Sun Jun 03 '20 at 14:38
  • 1
    If `os.execute` is naive about CMD'sbehavior, you may need to wrap the entire command in double quotes, in particular if it starts with a quoted path, because CMD will strip the first and last quotes. For example, run `'""C:\\Python34\\python.exe" "C:/Folder/abcd.py""'`. – Eryk Sun Jun 03 '20 at 14:42
  • `I am not getting result.` - What result do you mean? The exit code of python process? Or the stdout of python process? – Egor Skriptunoff Jun 05 '20 at 12:14

0 Answers0