[英]Execute python script in console via bash script with double-click
I have a python script, that runs fine if i run in on the console with python3 script.py
.我有一个 python 脚本,如果我使用
python3 script.py
在控制台上运行,它运行良好。 For some reason, the script should be executed via a bash-script "start.sh".出于某种原因,该脚本应通过 bash 脚本“start.sh”执行。 A MWE would be
MWE 将是
#!/bin/bash
python3 GUIpyPCS.py
When I run the script by double-clicking it, it doesent open a terminal window.当我通过双击运行脚本时,它不会打开终端 window。 Hence, the python script is executed invisibly in the background and not on a new console window.
因此,python 脚本在后台不可见地执行,而不是在新控制台 window 上执行。
How can I ensure, that the python script is executed on a console by double-clicking the bash-script?我如何确保通过双击 bash 脚本在控制台上执行 python 脚本? Is there something I can add to the bash script?
有什么可以添加到 bash 脚本的内容吗? I am currently testing on Kubuntu 20.04, but the solution should also applicable to other distributions/window managers.
我目前正在 Kubuntu 20.04 上进行测试,但该解决方案也应该适用于其他发行版/窗口管理器。
---------- Assumptions ---------- ---------- 假设 ----------
---------- In your script do ---------- ---------- 在你的脚本中做 ----------
read
command, to keep the window opened until you are doneread
命令,以保持 window 处于打开状态,直到完成 ---------- Ex ---------- - - - - - 前任 - - - - -
#!/bin/bash
#
xterm -e "/bin/ls /etc; read" &
---------- Details ---------- - - - - - 细节 - - - - -
the -e
option to xterm
is the command that will be executed in the new window xterm
的-e
选项是将在新的 window 中执行的命令
I put /bin/ls /etc; read
我把
/bin/ls /etc; read
/bin/ls /etc; read
instead of your script. /bin/ls /etc; read
而不是您的脚本。 You would put your_script.bash arg1 arg2; read
你会把
your_script.bash arg1 arg2; read
your_script.bash arg1 arg2; read
you could do something similar with gnome-terminal
instead of xterm
你可以用
gnome-terminal
而不是xterm
做类似的事情
the read
is not essential, it could be a sleep 5
for example. read
不是必需的,例如可以是sleep 5
。 Or if your script already has a delay or something, you might not need anything.或者,如果您的脚本已经有延迟或什么,您可能不需要任何东西。
I used xterm
since it is available on all distributions, which ever window manager you use.我使用了
xterm
,因为它适用于所有发行版,无论您使用哪种 window 管理器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.