修改 start.sh 中 display_found 变量的赋值方式
This commit is contained in:
parent
42ee4ca734
commit
6896dd9593
42
start.sh
42
start.sh
@ -23,17 +23,17 @@ cd /home/unitree/robot_face_rec || {
|
||||
echo "Env before display detection: DISPLAY=$DISPLAY, XAUTHORITY=$XAUTHORITY"
|
||||
} >> "$LOG_FILE"
|
||||
|
||||
# --- 动态检测 DISPLAY 的逻辑 ---
|
||||
# 方法:尝试从正在运行的 Xorg / X 进程环境中读取 DISPLAY
|
||||
|
||||
display_found=""
|
||||
# --- DISPLAY 设置逻辑 ---
|
||||
# 使用默认DISPLAY值:0,这是Linux系统中最常见的显示编号
|
||||
display_found=":0"
|
||||
echo "Using default DISPLAY: :0"
|
||||
|
||||
for pid in $(pgrep Xorg); do
|
||||
if [ -r /proc/$pid/environ ]; then
|
||||
disp=$(tr '\0' '\n' < /proc/$pid/environ | grep '^DISPLAY=' | cut -d'=' -f2-)
|
||||
if [ -n "$disp" ]; then
|
||||
display_found="$disp"
|
||||
echo "Chosen from Xorg process: $disp"
|
||||
echo "Chosen DISPLAY from Xorg process: $disp"
|
||||
break
|
||||
fi
|
||||
fi
|
||||
@ -43,20 +43,38 @@ done
|
||||
if [ -z "$display_found" ]; then
|
||||
# 常见默认::0
|
||||
display_found=":0"
|
||||
echo "Chosen default"
|
||||
echo "Chosen default DISPLAY: :0"
|
||||
fi
|
||||
|
||||
export DISPLAY="$display_found"
|
||||
|
||||
# 从Xorg命令行参数中获取正确的XAUTHORITY路径
|
||||
xauth_path=""
|
||||
for pid in $(pgrep Xorg); do
|
||||
if [ -r /proc/$pid/cmdline ]; then
|
||||
cmdline=$(tr '\0' ' ' < /proc/$pid/cmdline)
|
||||
xauth_path=$(echo "$cmdline" | grep -o "-auth [^ ]*" | cut -d' ' -f2)
|
||||
if [ -n "$xauth_path" ]; then
|
||||
break
|
||||
fi
|
||||
fi
|
||||
done
|
||||
|
||||
# 如果没有找到,使用默认路径
|
||||
if [ -z "$xauth_path" ]; then
|
||||
xauth_path="/home/unitree/.Xauthority"
|
||||
# 尝试更常见的gdm路径
|
||||
if [ -f "/run/user/1000/gdm/Xauthority" ]; then
|
||||
xauth_path="/run/user/1000/gdm/Xauthority"
|
||||
fi
|
||||
fi
|
||||
|
||||
export XAUTHORITY="$xauth_path"
|
||||
|
||||
{
|
||||
echo "Chosen DISPLAY = $DISPLAY"
|
||||
} >> "$LOG_FILE"
|
||||
|
||||
# XAUTHORITY:假设用户的 .Xauthority 存在于 home 目录
|
||||
export XAUTHORITY="/home/unitree/.Xauthority"
|
||||
{
|
||||
echo "Using XAUTHORITY = $XAUTHORITY"
|
||||
} >> "$LOG_FILE"
|
||||
|
||||
# 最终执行 Python 程序(不后台化,用 exec 替换进程)
|
||||
exec python face_rec.py >> "$LOG_FILE" 2>&1
|
||||
exec python face_rec.py >> "$LOG_FILE" 2>&1
|
||||
Loading…
Reference in New Issue
Block a user