在Windows 10桌面快捷方式启动Cygwin X11 GUI应用的问题求助
I’ve run into this exact headache with Cygwin GUI apps and desktop shortcuts—let’s break down what’s going wrong and fix it step by step.
The Core Issue with Your Current Setup
Your shortcut is overcomplicating things by using xterm alongside run.exe, plus the -display parameter has a critical typo (missing the colon in 0.0). Worse, xterm isn’t needed here at all—run.exe is built to launch Cygwin processes without a visible terminal window, so adding xterm creates unnecessary conflicts with the startxwin session you’re already initializing.
Step 1: Simplify the Desktop Shortcut
Replace your existing shortcut command with this streamlined version:
C:\cygwin64\bin\run.exe /bin/bash -l "/cygdrive/c/Users/MYNAME/atril-launcher.sh"
What this does:
run.exe: Spawns the Cygwin process in the background without popping up a terminal./bin/bash -l: Starts a login shell, which automatically loads your~/.bashrc(where you setDISPLAYand auto-startstartxwin).- Quoting the script path ensures spaces in usernames or folder names are handled correctly.
Step 2: Refine Your Atril Launch Script
Update your atril-launcher.sh to be more robust—we’ll add a check to guarantee startxwin is running before launching Atril, and strip out unnecessary cruft:
#!/bin/bash # Check if startxwin is active; launch it if not if ! pgrep startxwin > /dev/null; then startxwin > /dev/null 2>&1 & # Give the X server a couple seconds to fully initialize sleep 2 fi # Launch Atril directly /bin/atril.exe
Key improvements:
pgrep startxwin: Verifies the X server is running, so we don’t rely solely on.bashrcto start it (which might not fire in some edge cases).- The short
sleepprevents race conditions where Atril tries to connect before the X server is ready. - Removed
nohupand extrasleep—run.exealready handles background execution for you.
Step 3: Double-Check Permissions and Environment
- Make sure your script has execute permissions (you said it’s correct, but it never hurts to confirm):
chmod +x /cygdrive/c/Users/MYNAME/atril-launcher.sh - Confirm your
~/.bashrcstill has these correct, modern Cygwin lines (I cleaned up the check for better reliability):export DISPLAY=:0.0 if command -v startxwin > /dev/null 2>&1; then startxwin > /dev/null 2>&1 & fi
Troubleshooting: Capture Error Logs
If it still fails silently, modify the shortcut to log output so you can diagnose exactly what’s breaking:
C:\cygwin64\bin\run.exe /bin/bash -l "/cygdrive/c/Users/MYNAME/atril-launcher.sh" > "C:\Users\MYNAME\launch-log.txt" 2>&1
Check launch-log.txt for errors like missing dependencies, incorrect DISPLAY values, or failed startxwin launches.
内容的提问来源于stack exchange,提问作者AJM

