我有以下python代码。如您所见,它非常简单。目前,它正在做的是:
- 更改一些环境变量
- 然后更改cwd
- 使用bash命令创建一个.sh文件,该命令会向我发送电子邮件
现在,当我运行该程序时,将首先自动发送此电子邮件。但是,然后我创建了一个Tkinter GUI,它只有一个喜欢该按钮的函数,该函数每次按下电子邮件都会发送一次。如果您发现它与GUI外部使用的命令完全相同。
然后我的问题是,为什么当从GUI外部而不是从GUI本身读取命令时,电子邮件发送没有问题?即Tkinter不喜欢该命令的是什么以及如何解决它?
注意我正在Windows 10计算机上使用python 3.6。另外,我认为提到“ ts”是cygwin环境中的可执行文件,可以用来依次排布不同的命令
,可能很重要。编辑我遇到的任务后台处理程序错误是: 进出口配置文件/etc/exim.conf的所有者,组或模式错误 发送消息时出错,孩子退出了1()。 无法发送消息。
任何帮助您了解正在发生的事情,将不胜感激! 让我知道您是否需要进一步澄清。
谢谢
#Proc_file_preorganizer
#By Rafael Canelon Nov 26/2019
from pathlib import Path
import tkinter as tk
from tkinter import ttk
import tkinter.filedialog
import os
import subprocess as sp
LARGE_FONT = ("Verdana",12)
os.environ["PATH"] = "C:\Windows\system32;"+ "C:\Windows;" + "C:\Windows\system32\WBem"
os.environ["LATOOLS_HOME"] = "C:\\LAStools\\opt\LAStools"
os.environ["GMT_HOME"] = "C:\\LAStools\opt\\gmt5"
os.environ["GDAL_HOME"] = "C:\\LAStools\opt\\GDAL"
os.environ["CYGWIN_PATH"] = r"C:\LAStools\bin;C:\LAStools\usr\local\bin;C:\LAStools\usr\bin"
os.environ["GEORUN"] = r"C:\Program Files\Riegl_LMS\RiWORLD"
os.environ["TMP"] = "C:\LAStools\tmp"
os.environ["GMT5_SHAREDIR"] = os.getenv("GMT_HOME") + "\gmt5\share"
os.environ["GDAL_DATA"] = os.getenv("GDAL_HOME") + "\gdal-data"
os.environ["GDAL_DRIVER_PATH"] = os.getenv("GDAL_HOME") + "\gdal_plugins"
os.environ["PROJ_LIB"] = os.getenv("GDAL_HOME") + "\projlib"
os.environ["PATH"] =os.environ["CYGWIN_PATH"] + ";" + os.environ["PATH"]+ ";" + os.environ["LATOOLS_HOME"]+"\\bin;" + os.environ["GMT_HOME"]+"\\bin;" + os.environ["GDAL_HOME"] + ";" + os.environ["GEORUN"]
os.chdir("E:/4319292a")
print("The working directory changed to: ",os.getcwd(),"\n")
with open("script.sh",'w+',newline="\n") as emailscript:
emailscript.write("#!/bin/bash \n ts mutt rafaelc@airborneimaginginc.com -s \"this is a test\"\n")
Ecmd = "bash -ic ./script.sh"
sp.run(Ecmd)
print("Check your Email and TS")
class HowToReigl(tk.Tk):
def __init__(self,*args,**kwargs):
tk.Tk.__init__(self,**kwargs)
#tk.TK.iconbitmap(self,default="filename.ico") use this line once you have an icon to place on the window. you will need a website to actully make an ico file
tk.Tk.wm_title(self,"Proc_File_Selector")
container = tk.Frame(self,width=10,height=10,borderwidth=5)
container.pack(side="top",fill="both",expand=True)
container.grid_rowconfigure(0,weight=1)
container.grid_columnconfigure(0,weight=1)
self.frames = {}
frame = StartPage(container,self)
self.frames[StartPage] = frame
frame.grid(row=0,column=0,sticky="nsew")
self.show_frame(StartPage)
def show_frame(self,cont):
frame = self.frames[cont]
frame.tkraise()
class StartPage(tk.Frame):
def __init__(self,parent,controller):
tk.Frame.__init__(self,parent)
label = ttk.Label(self,text="airborne Imaging Inc. Application",font=LARGE_FONT)
label.grid(row=0,column=0)
button3 = ttk.Button(self,text="Test",command= lambda: test_emailsend())
button3.grid(row=21,column=0)
##--------------------------------------------------------------------------------------------------------------------------------------------------------------
def test_emailsend():
with open("script.sh",newline="\n") as emailscript:
emailscript.write("#!/bin/bash \n ts mutt rafaelc@airborneimaginginc.com -s \"this is a test\"\n")
Ecmd = "bash -ic ./script.sh"
sp.run(Ecmd)
print("Check your Email and TS")
##--------------------------------------------------------------------------------------------------------------------------------------------------------------
app = HowToReigl()
app.mainloop()