[英]How to call a python script on a new shell window from python code?
[英]Run a Python Script in a new window from a shell script ubuntu
這似乎是一個愚蠢的問題。
我想從一個 shell 腳本文件在另一個命令行窗口中運行 python 腳本,該文件在我的一台服務器上打開我的所有程序。
目前,python 腳本在運行 shell 腳本的同一命令行窗口中打開。
我用谷歌搜索了一下,沒有找到與此相關的任何內容。
提前致謝。
如果我理解正確,你有一個服務器,它連接了一個屏幕,你制作了一個 shell 屏幕來打開一個新終端並運行附加到該終端的一組給定程序。
在我看來,您不希望在腳本中使用它,而是應該尋找一個 init 系統,例如 systemd,它在 Ubuntu 中可用。 簡單地說,systemd 會初始化並殺死在后台運行的進程(通常稱為守護進程)。
要創建 systemd 單元文件,請在/etc/systemd//system
創建一個新文件,將其命名為example.service
,並將以下內容寫入其中:
[Unit]
Description=*Write description here*
Type=simple
Restart=always
RestartSec=1
User=*Write user here*
ExecStart=*Write command you wish to run here*
[Install]
WantedBy=multi-user.target
現在你可以在后台啟動這個程序:
$ systemctl daemon-reload
$ systemctl start example
您還可以阻止它運行:
$ systemctl stop example
甚至在啟動時啟用它,以便它保持關閉/重啟:
$ systemctl enable example
您可以通過以下方式獲取此程序的輸出:
$ systemctl status example
有關 systemd 和所有配置選項的更多信息,您可以使用man systemd
(很長)或谷歌查看手冊頁以了解您希望實現的特定問題或功能。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.