【问题标题】:Open terminal in same window (Ubuntu)在同一窗口中打开终端(Ubuntu)
【发布时间】:2018-05-16 15:11:26
【问题描述】:

我有一个问题。我想创建一个 .desktop 可执行文件,它将在终端中执行命令。我也使用了下面的代码。

[Desktop Entry]
Version=1.0
Type=Application
Terminal=true
Exec=python2 ./main.py
Name=Air Hockey
Comment=This runs Air Hockey in one click
Icon=./logo.png

使用此代码打开的终端具有默认目录作为其地址。我想在执行此 (.desktop) 文件的目录中启动它。

我尝试过使用 %k,但结果证明没有用。

【问题讨论】:

  • 你为什么关心它运行在哪个目录?如果这很重要,请在启动 Python 脚本时更改目录。

标签: python shell ubuntu terminal


【解决方案1】:

以下命令用于删除目录名称中的空格。

Exec=bash -c 'cd $(dirname %k) && python2 main.py'

参考:https://askubuntu.com/questions/47775/how-can-i-set-the-path-variable-in-a-desktop-file-to-be-relative-to-the-locat

【讨论】:

    【解决方案2】:

    %k 返回带有路径的桌面文件的名称。

    假设 main.py 是您的脚本的名称

    你可以试试:

    Exec=python2 $(dirname %k)/main.py
    

    希望对您有所帮助。

    【讨论】:

    • 这不起作用。我觉得这在 Ubuntu 中是不可能的。
    • 对不起,我根本不使用python,但你可以在桌面文件中设置Path。Path=你的目录和Exec=python2 main.py。如果你想保持终端打开,使用 python2 -i main.py。
    猜你喜欢
    • 2013-10-28
    • 2020-08-15
    • 1970-01-01
    • 2019-02-17
    • 2014-07-20
    • 2010-12-20
    • 1970-01-01
    • 2020-04-27
    • 2011-01-18
    相关资源
    最近更新 更多