How to run *.py(w) _without command line popping out_?

General discussion about LÖVE, Lua, game development, puns, and unicorns.
User avatar
417_TheFog
Prole
Posts: 8
Joined: Sun Dec 29, 2024 1:37 pm

How to run *.py(w) _without command line popping out_?

Post 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?
Last edited by 417_TheFog on Sat Jan 04, 2025 12:44 pm, edited 1 time in total.
RNavega
Party member
Posts: 401
Joined: Sun Aug 16, 2020 1:28 pm

Re: How to run -.py without command line popping out?

Post by RNavega »

A Python installation comes with python.exe and pythonw.exe, this is their difference:
https://stackoverflow.com/a/30313091
User avatar
417_TheFog
Prole
Posts: 8
Joined: Sun Dec 29, 2024 1:37 pm

Re: How to run -.py without command line popping out?

Post by 417_TheFog »

RNavega 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
the thing is it still appears :?
User avatar
dusoft
Party member
Posts: 676
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: How to run -.py without command line popping out?

Post by dusoft »

Why do you need to run something in a different language, ask yourself that as a first thing.
User avatar
417_TheFog
Prole
Posts: 8
Joined: Sun Dec 29, 2024 1:37 pm

Re: How to run -.py without command line popping out?

Post 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.
User avatar
dusoft
Party member
Posts: 676
Joined: Fri Nov 08, 2013 12:07 am
Location: Europe usually
Contact:

Re: How to run *.py(w) _without command line popping out_?

Post 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.
kov_serg
Prole
Posts: 12
Joined: Wed Dec 18, 2024 4:38 pm

Re: How to run *.py(w) _without command line popping out_?

Post 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()
User avatar
417_TheFog
Prole
Posts: 8
Joined: Sun Dec 29, 2024 1:37 pm

Re: How to run *.py(w) _without command line popping out_?

Post 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 :awesome: !
RNavega
Party member
Posts: 401
Joined: Sun Aug 16, 2020 1:28 pm

Re: How to run *.py(w) _without command line popping out_?

Post 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:
  • love.exe (no console)
  • 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.
kov_serg
Prole
Posts: 12
Joined: Wed Dec 18, 2024 4:38 pm

Re: How to run *.py(w) _without command line popping out_?

Post 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.
Post Reply

Who is online

Users browsing this forum: Semrush [Bot] and 3 guests