我是Raspbian的新手。我在RPi + +官方7英寸显示器上的Raspbian上有一个Mono WinForms应用程序。当我通过UI(双击文件)和终端(start-app.sh
)执行/home/pi/scannerapp/start-app.sh
脚本时,它运行良好。 / p>
脚本(start-app.sh
):
#!/bin/bash
/usr/bin/mono '/home/pi/scannerapp/Re-Express Scanner WinForms.exe'
我使用以下命令编辑了rc.local文件:
exec 2> /tmp/rc.local.log # send stderr from rc.local to a log file
exec 1>&2 # send stdout to the same log file
set -x # tell sh to display commands before execution
/home/pi/scannerapp/start-app.sh &
exit 0
在启动时,该应用程序无法运行。我在日志中找到以下内容:
Unhandled Exception:
System.TypeInitializationException: The type initializer for 'System.Windows.Forms.XplatUI' threw an exception. ---> System.ArgumentNullException: Could not open display (X-Server required. Check your DISPLAY environment variable)
Parameter name: Display
at System.Windows.Forms.XplatUIX11.SetDisplay (System.IntPtr display_handle) [0x00435] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
at System.Windows.Forms.XplatUIX11..ctor () [0x00077] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
at System.Windows.Forms.XplatUIX11.GetInstance () [0x0001c] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
at System.Windows.Forms.XplatUI..cctor () [0x0007d] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
--- End of inner exception stack trace ---
at System.Windows.Forms.Application.EnableVisualStyles () [0x00006] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
at Re_Express_Scanner_WinForms.Program.Main () [0x00001] in <52b5a9f59ae647c0a7c47e5736c3742e>:0
[ERROR] FATAL UNHANDLED EXCEPTION: System.TypeInitializationException: The type initializer for 'System.Windows.Forms.XplatUI' threw an exception. ---> System.ArgumentNullException: Could not open display (X-Server required. Check your DISPLAY environment variable)
Parameter name: Display
at System.Windows.Forms.XplatUIX11.SetDisplay (System.IntPtr display_handle) [0x00435] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
at System.Windows.Forms.XplatUIX11..ctor () [0x00077] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
at System.Windows.Forms.XplatUIX11.GetInstance () [0x0001c] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
at System.Windows.Forms.XplatUI..cctor () [0x0007d] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
--- End of inner exception stack trace ---
at System.Windows.Forms.Application.EnableVisualStyles () [0x00006] in <d5b72d15d4f7424c8a1538e3f19ec2e3>:0
at Re_Express_Scanner_WinForms.Program.Main () [0x00001] in <52b5a9f59ae647c0a7c47e5736c3742e>:0
如果尝试通过SSH运行start-app.sh
脚本,则会遇到相同的异常。
感谢您的帮助。 谢谢!
答案 0 :(得分:0)
我最终从rc.local中删除了我的编辑,并使用sudo nano编辑了/ etc / xdg / lxsession / LXDE-pi / autostart中的start-app.sh脚本。现在正在启动。据我了解,从rc.local文件调用脚本是在X显示环境之外进行的,因此,X显示错误以及为什么需要从显示环境(/ lxde-pi / autostart)中调用它。
有关自动运行的GUI应用程序的更多信息,请参见此: http://www.raspberry-projects.com/pi/pi-operating-systems/raspbian/auto-running-programs-gui