You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Python菜单脚本通过xterm启动二进制程序报错问题咨询

问题原因

xterm的参数规则要求,所有要在xterm终端内执行的命令,必须放在-e参数之后。你之前的写法没有加-e,xterm会把你写的二进制路径误判为自身的启动参数,所以抛出了参数不合法的错误。

修复后的代码
def name(self):
    os.system('xterm -bg black -fg white -geometry 150x20 -title name -fa Monospace -e /path/script-bynary /directory/ output.txt &')
补充注意点
  • 原代码中def name(self)后缺少Python语法要求的冒号:,需要补上避免语法报错
  • 如果你的二进制路径、目录路径或者输出文件名包含空格,需要给对应路径加引号包裹,示例:
    os.system('xterm -bg black -fg white -geometry 150x20 -title name -fa Monospace -e "/path/script binary" "/my dir/" "output name.txt" &')
    
  • 也可以替换os.system为更安全的subprocess模块调用,避免字符串拼接的注入风险,示例:
    import subprocess
    def name(self):
        subprocess.Popen([
            'xterm', '-bg', 'black', '-fg', 'white', '-geometry', '150x20',
            '-title', 'name', '-fa', 'Monospace', '-e',
            '/path/script-bynary', '/directory/', 'output.txt'
        ])
    

内容的提问来源于stack exchange,提问作者esse_emme

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.30 16:39:04