在pyside中内置了一个exe的启动程序,由程序创建一个快捷方式
import winshell
# 读取当前路径下录频软件
file = os.path.join(os.getcwd(), 'Record/bin/64bit/obs64.exe')
if os.path.exists(file):
shortcut_path = os.path.join(os.getcwd(), 'obs.lnk')
with winshell.shortcut(shortcut_path) as shortcut:
shortcut.path = file
shortcut.write()
后来发现obs还是使用了上级目录无法使用,因此采用Popen调用并设置初始工作目录位置
import psutil
import subprocess
working_directory = os.path.join(os.getcwd(), 'Record/bin/64bit')
for process in psutil.process_iter(['pid', 'name']):
if process.info['name'] == 'obs64.exe':
return
# 启动录制进程
self.recording_process = subprocess.Popen(
os.path.join(working_directory, 'obs64.exe'),
cwd=working_directory, # 设置工作目录
shell=True # 如果 .exe 文件需要命令行参数或 shell 环境,请设置为 True
)
版权说明
本文地址:http://www.liuyangdeboke.cn/?post=50
未标注转载均为本站远程,转载请注明文章出处:
发表评论