0
1

More than 5 years have passed since last update.

PACEMAKER > linux > LXTerminalを起動してPythonスクリプトを実行する > -eオプション | .desktopファイルでの設定例

Last updated at Posted at 2017-11-02
動作環境
Raspberry Pi 2 Model B (以下RPi)
Raspbian Jessie
Python 2.7.9

プロジェクト開始: link

LXTerminalを起動してPythonスクリプトを実行するには-eオプションを指定すれば良さそう。

~/WORK/PACEMAKER_171026/hello_171103.py
#!/usr/bin/env python
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
import time
from datetime import datetime as dt

while True:
    now = dt.now().strftime('%Y-%m-%d %H:%M:%S')
    print(now)
    time.sleep(1)

念のため、上記のスクリプトにchmod +xしておく。

以下を実行する。

$ lxterminal -e ~/WORK/PACEMAKER_171026/hello_171103.py

qiita.png

スクリプトが始まらない > パス指定ミス

.desktopファイルのEXECに上記のlxterminalコマンドを記載しxdg-openでテストしたが、Pythonスクリプトが起動する様子が見られない。

RPiの自動起動で確認したが、LXTerminalが起動時にPythonスクリプトが実行されなかった。 

~/WORKというパスが認識されてなかったようだ。/home/pi/WORKにすると動いた。

.desktopファイル設定例

PACEMAKER-setup.desktop
[Desktop Entry]
Exec=lxterminal --geometry=200x50 -e /home/pi/WORK/PACEMAKER_171026/hello_171103.py 
Type=Application
Name=PACEMAKER
Comment=Keep your pace as healthy as possible
Terminal=true

上記のファイルを/home/pi/.config/autostartに置いておくことで、自動ログイン後にLXTerminalが起動し、Pythonスクリプトが動くようになった。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1