English 中文(简体)
1. 露台式照像
原标题:Run Python script without Windows console appearing

在Windows XP中,没有一时出现指挥时,是否有办法操作一种灰色文字? 我常常需要将“善待”与“沙尔”同起来,即使我的手稿没有产出,如果我从没有工作能力就把一只空壳搁置起来,在消失之前,二只剩下一只空壳。 是否有办法防止这种情况? 某些产出的重新方向或许会?

最佳回答

如果没有迅速指挥,则由餐厅管理。 问题在于,沙尔语译员,即沙尔语,与ole子系统相联,以生产青.素产量(因为90%的病例)—— p。 相反,外部与全球倡议的子系统挂钩,而Windows不会为它创造光辉的产出窗口,除非它要求这样做。

条讨论了GUI的节目编排方式,也提到了pythonw.exe。 它还有益地指出,如果您的档案用.pyw而不是py,则标准Windows安装器将正确设立协会,并在pythonw.exe中操作你的粉碎。

在您的案例中,它不像问题一样健全,而是依靠 p。 您的“视窗”具体应用——在MacOS X上找到了其他解决办法。

问题回答

如果你把你的档案称为“.pyw”的延伸,那么窗户就会用 p子执行。 口译。 这不会为管理你的文字打开大门。

该系统将使用所有Windows版本:

1. Creat “Runner.bat file with Notepad (or any other text Editors), 并插入以下内容:

@echo off
python server.py

在这里,server.py是你想要跑的 Python。

2. Creating “Rungust.vbs file with Notepad and内插入:

CreateObject("Wscript.Shell").Run "runner.bat",0,True

<>3>。 运行“Rungust.vbs文档,双向点击和你的喷口将不出现任何明显的ole窗。

页: 1 (关于Windows 10, 大部分在C:Users[USERNAME]AppDataRoamingMicrosoftvilStart MenuProgramsStartup下)

最佳做法

然而,我尝试了上述方法,由于我的手稿中的一名时间长,一名少年仍然露头并迅速消失。 最后,我发现以下法典:

import ctypes
import os
import win32process

hwnd = ctypes.windll.kernel32.GetConsoleWindow()      
if hwnd != 0:      
    ctypes.windll.user32.ShowWindow(hwnd, 0)      
    ctypes.windll.kernel32.CloseHandle(hwnd)
    _, pid = win32process.GetWindowThreadProcessId(hwnd)
    os.system( taskkill /PID   + str(pid) +   /f )

Quite easy in Win10:
Open a PowerShell and type this commands:

type nul > openWindowed.vbs
type nul > main.py
notepad openWindowed.vbs

下一次会议到开放式散会。 档案:

Set WshShell = CreateObject("WScript.Shell") 
WshShell.Run chr(34) & "C:Userspath	omain.py" & Chr(34), 0
Set WshShell = Nothing

<>m>vbs文档将执行main.py文档,不开放一厘米。 我在make.py文档上用了这片话,因为我不知道打字。

更换你的窗户保护人。 安装pyinstaller的包裹,使用<代码>pip 安装pyinstaller。

在安装了开放式的圆柱和打字后pyinstaller www.un.org/Depts/DGACM/index_french.htm

将档案延伸至.pyw,在您的文字开始之前添加以下一行(相应改动):

#! c:\Users\sohra\AppData\Local\Programs\Python\Python38\pythonw.exe

现在,如果你在档案上再次点击,就会由平子执行。 不用ole窗。

The stanza work well through python.exe,但该编码没有pythonw.exe。 更糟糕的是,没有一种可行的机制来输出<代码>sysoutsyserr。 因此,我写了以下C#方案,在没有指挥窗口的情况下开办假日:

public class Program
{
  private string python = @"D:LibsPython38Python38_64python.exe";
  private string args = "mdx_server.py";
  private string wkDir = "D:\Program Files\mdx-server";
    
  public static void Main(string[] args) {
    Program app = new Program();
    Console.WriteLine(app.python + " " + app.args + " " + app.wkDir);
    app.Exec();
    Console.WriteLine("Start done!");
  }

  private void runThread() {
    Process process = new Process();
    try {
      process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
      process.StartInfo.Arguments = args;

      process.StartInfo.CreateNoWindow = true;
      process.StartInfo.FileName = python;
      process.StartInfo.WorkingDirectory = wkDir;

      process.StartInfo.UseShellExecute = false;
      process.Start();
    } catch (Exception ex) {
      Console.WriteLine(ex.Message);
    }
  }

  public void Exec() {
    Thread _worker = new Thread(runThread);
    _worker.Start();
  }
}

视窗有2 选项,我想:

  • <><>>

    1. py文档延伸至pyw, 并替换python.exe改为pythonw.exe,其行文如下(请注意替换<your_username>/<your_path_to>):

      #! C:\Users\<your_username>\<your_path_to>\Scripts\pythonw.exe
      
    2. 双重点击.pyw 操作文件。

    3. 选择而言,你还可以创建<>星号>星号/星号>至<代码>>。

  • <><>>>

    1. 查阅<代码>py 文档延伸和替换pythonw.exe,>python.exe,其第一行如下(代之以<your_username>/<your_path_to>):

      #! C:\Users\<your_username>\<your_path_to>\Scripts\python.exe
      
    2. 使用<代码>.vbs (Visual Basic code)文档,其内容为.py文档(可使用.vbs文档,以同时发射.bat文档,而无需显示:

      Set WshShell = CreateObject("WScript.Shell") 
      WshShell.Run "C:Users<your_username><your_path_to>Scriptspython.exe C:Users<your_username><your_path_to>script.py", 0, True
      Set WshShell = Nothing
      
    3. 页: 1

    4. 选择而言,你也可以创建<>星号>,到<代码>.vbs文档,以定制其 名称>、,作为final releaseer

当你安装Pyinstaller时,你将能够将.py转换成.exe。 在这种环境中,你可以改变是否展示假日开立的 con窗。

I had the same problem. I tried many options, and all of them failed But I tried this method, and it magically worked!!!!!

So, I had this python file (mod.py) in a folder, I used to run using command prompt When I used to close the cmd the gui is automatically closed.....(SAD), So I run it as follows C:....>pythonw mod.py Don t forget pythonw "w" is IMP





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...