Page 1 of 2
How to run *.py(w) _without command line popping out_?
Posted: Sat Jan 04, 2025 8:01 am
by 417_TheFog
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?
Re: How to run -.py without command line popping out?
Posted: Sat Jan 04, 2025 9:38 am
by RNavega
A Python installation comes with python.exe and python
w.exe, this is their difference:
https://stackoverflow.com/a/30313091
Re: How to run -.py without command line popping out?
Posted: Sat Jan 04, 2025 11:51 am
by 417_TheFog
the thing is it still appears
Re: How to run -.py without command line popping out?
Posted: Sat Jan 04, 2025 12:06 pm
by dusoft
Why do you need to run something in a different language, ask yourself that as a first thing.
Re: How to run -.py without command line popping out?
Posted: Sat Jan 04, 2025 12:14 pm
by 417_TheFog
dusoft wrote: ↑Sat Jan 04, 2025 12:06 pm
Why do you need to run something in a different language
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_?
Posted: Sat Jan 04, 2025 12:47 pm
by dusoft
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.
Re: How to run *.py(w) _without command line popping out_?
Posted: Sat Jan 04, 2025 1:39 pm
by kov_serg
Code: Select all
-- conf.lua
function love:conf()
self.console=true
end
To disable popups try to enabled console in config
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()
Re: How to run *.py(w) _without command line popping out_?
Posted: Sat Jan 04, 2025 3:02 pm
by 417_TheFog
dusoft wrote: ↑Sat Jan 04, 2025 12:47 pm
provide some Lua code.
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")
kov_serg wrote: ↑Sat Jan 04, 2025 1:39 pm
...
oh wow, thanks a lot
!
Re: How to run *.py(w) _without command line popping out_?
Posted: Sat Jan 04, 2025 4:05 pm
by RNavega
417_TheFog wrote: ↑Sat Jan 04, 2025 3:02 pm
Code: Select all
os.execute("pythonw.exe Script.pyw 1>stdout.txt 2>stderr.txt")
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:
- lovec.exe (forced console)
I set each to like the F5 and F6 shortcut keys on Notepad++ (plus the path to the current directory), so if I want to run w/ console output, I hit the key that's bound to lovec.exe.
Re: How to run *.py(w) _without command line popping out_?
Posted: Sun Jan 05, 2025 7:10 am
by kov_serg
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.