コンテキスト - Musicフォルダを読み込んで、各音楽ファイルのVLCプレーヤーを一度に1つずつ開くPythonスクリプトがあります(1曲が再生され、VLCが終了し、など)。 IDEまたはターミナルからPythonスクリプトを実行すると、スクリプトは正常に実行されます。しかし、私がCronの仕事を通してそれを実行するとき、それは失敗する。CronジョブでスケジュールされたPythonスクリプトが失敗しました
Pythonスクリプト - テスト目的でループを無効にしました。
import os,subprocess
my_path = '/home/tushar/Music/Devotional/'
songs_list = os.listdir(my_path)
song_str = ''
#for song in songs_list:
#subprocess.run(["vlc", my_path+song])
subprocess.run(["vlc", "/home/tushar/PycharmProjects/Morning Devotional Songs/Ganesha.opus"])
のcrontab -e
47 10 * * * python3 /home/tushar/PycharmProjects/Morning\ Devotional\ Songs/main.py >> /var/log/myjob.log 2>&1
cronジョブログ -
> [000055ed64567cf8] core interface error: no suitable interface module
> [000055ed6445a148] core libvlc error: interface "globalhotkeys,none"
> initialization failed [000055ed64567cf8] dbus interface error: Failed
> to connect to the D-Bus session daemon: Unable to autolaunch a
> dbus-daemon without a $DISPLAY for X11 [000055ed64567cf8] core
> interface error: no suitable interface module [000055ed6445a148] core
> libvlc error: interface "dbus,none" initialization failed
> [000055ed6445a148] core libvlc: Running vlc with the default
> interface. Use 'cvlc' to use vlc without interface. [000055ed64567cf8]
> qt4 interface error: Could not connect to X server [000055ed64567cf8]
> skins2 interface error: cannot initialize OSFactory [000055ed64567cf8]
> [cli] lua interface: Listening on host "*console". VLC media player
> 2.2.4 Weatherwax Command Line Interface initialized. Type `help' for help.
>
> Shutting down. [000055ed64567cf8] [cli] lua interface: Requested
> shutdown. [000055ed64567cf8] [cli] lua interface error: Error loading
> script /usr/lib/vlc/lua/intf/cli.luac: lua/intf/modules/host.lua:279:
> Interrupted. [00007f977c0178c8] core stream error: cannot pre fill
> buffer
はどのように問題を修正しますか?
これは、cronで実行されるジョブにDISPLAY環境変数が設定されていない(デフォルトでは非GUIモード)ため、表示サーバーと通信できないためです。表示変数(hackish)を設定するか、エラーが 'cvlc'を使うように設定します。 – SuperSaiyan