1. 当前位置:网站首页 > Python

python 创建快捷方式


在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
    )

本文最后更新于2023-9-11,已超过 3个月没有更新,如果文章内容或图片资源失效,请留言反馈,我们会及时处理,谢谢!
版权说明

本文地址:http://www.liuyangdeboke.cn/?post=50
未标注转载均为本站远程,转载请注明文章出处:

发表评论

联系我们

在线咨询:点击这里给我发消息

微信号:17721538135

工作日:9:00-23:00,节假日休息

扫码关注