How to run *.py from *.lua or at least properly execute python code without command line popping out???
(on Windows 11)
NOTE: it still appears even with -.pyw. The problem is probably in the ways *.py(w) is executed - os.execute and io.popen. How then?
How to run *.py(w) _without command line popping out_?
- 417_TheFog
- Prole
- Posts: 8
- Joined: Sun Dec 29, 2024 1:37 pm
How to run *.py(w) _without command line popping out_?
Last edited by 417_TheFog on Sat Jan 04, 2025 12:44 pm, edited 1 time in total.
Re: How to run -.py without command line popping out?
A Python installation comes with python.exe and pythonw.exe, this is their difference:
https://stackoverflow.com/a/30313091
https://stackoverflow.com/a/30313091
- 417_TheFog
- Prole
- Posts: 8
- Joined: Sun Dec 29, 2024 1:37 pm
Re: How to run -.py without command line popping out?
the thing is it still appearsRNavega wrote: ↑Sat Jan 04, 2025 9:38 am A Python installation comes with python.exe and pythonw.exe, this is their difference:
https://stackoverflow.com/a/30313091
Re: How to run -.py without command line popping out?
Why do you need to run something in a different language, ask yourself that as a first thing.
My boat driving game demo: https://dusoft.itch.io/captain-bradley- ... itius-demo
- 417_TheFog
- Prole
- Posts: 8
- Joined: Sun Dec 29, 2024 1:37 pm
Re: How to run -.py without command line popping out?
I need to use the API of one program and this API is only in python. I don't write everything in python because creating a distribution on it is a pain.
It's strange that you ask such a question, like bro a huge number of projects on github are multilingual because none of the languages is universal/optimized for any task.
Re: How to run *.py(w) _without command line popping out_?
It's still a relevant question. If it's your only option, fair enough, but if you want us to help you, you better provide some Lua code.
My boat driving game demo: https://dusoft.itch.io/captain-bradley- ... itius-demo
Re: How to run *.py(w) _without command line popping out_?
Code: Select all
-- conf.lua
function love:conf()
self.console=true
end
Another workaround is to use network
Code: Select all
-- main.lua
if not love then os.execute "love ." os.exit() end
os.execute "start /min python server.py"
local socket=require "socket"
local app={ text="press 1", t=0 }
function love.update(dt) app.t=app.t+dt end
function love.draw()
love.graphics.print(("%s t=%.2f"):format(app.text,app.t),10,10)
end
function command(cmd)
local s=socket.tcp() s:connect("127.0.0.1",32768)
s:send(cmd) local res=s:receive "*a" s:close()
return res
end
function love.keypressed(key)
if key=='q' or key=='escape' then command "quit" end
if key=='escape' then love.event.quit() end
if key=='1' then app.text=command "hello" end
end
Code: Select all
# server.py
import socket,sys
s=socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.bind(('127.0.0.1',32768))
s.listen(5)
while True:
con,addr=s.accept()
buf=con.recv(1024)
print(buf)
con.send(buf+" from python\n")
con.close()
if buf=="quit": sys.exit()
- 417_TheFog
- Prole
- Posts: 8
- Joined: Sun Dec 29, 2024 1:37 pm
Re: How to run *.py(w) _without command line popping out_?
here. the problem is not in writing the code, but in the fact that I literally do not know what function to use.
Code: Select all
os.execute("pythonw.exe Script.pyw 1>stdout.txt 2>stderr.txt")
oh wow, thanks a lot !
Re: How to run *.py(w) _without command line popping out_?
Oh, I see. If the console was still coming up even with the Python side resolved, then as kov_serg pointed out, it might be LÖVE's console, which can be disabled through that conf.lua flag or also by not using that flag at all and running your programs with either:417_TheFog wrote: ↑Sat Jan 04, 2025 3:02 pmCode: Select all
os.execute("pythonw.exe Script.pyw 1>stdout.txt 2>stderr.txt")
- love.exe (no console)
- lovec.exe (forced console)
Re: How to run *.py(w) _without command line popping out_?
Even more io.popen has same behaviour. It pops up console window if no console enabled.
This problem inside love code.
But why you try to use python with love2d? You can use python pyglet for example.
This problem inside love code.
But why you try to use python with love2d? You can use python pyglet for example.
Who is online
Users browsing this forum: TurboYeti and 5 guests