【发布时间】:2014-07-03 23:05:51
【问题描述】:
我希望我的 c# 应用程序(我在树莓派上执行)在启动时运行 bash 脚本..
基本上:脚本位于/etc/init.d 并命名为mnw。我希望每当我的 c# 应用程序启动时,它都应该执行 mnw 脚本的一部分。
如果它是在终端中写的,它看起来像:
cd /etc/init.d
./mnw stop
我希望这发生在public static void Main() 的开头,我一直在尝试
ProcessStartInfo startInfo = new ProcessStartInfo() { FileName = "/dev/init.d/./mnw", Arguments = "stop", };
Process proc = new Process() { StartInfo = startInfo, };
proc.Start();
但它说 stop 是一个意想不到的论点,有什么想法吗?
【问题讨论】:
-
一个明显的错误 -
FileName = "/dev/init.d/./mnw"应该是FileName = "/etc/init.d/mnw",但我认为这是粘贴此问题时的拼写错误。 -
为什么不创建 bash 脚本呢?
-
这是 mnw if [ "$1" = "start" ] then start-stop-daemon --start --background -m --oknodo --pidfile /home/pi/p$ elif [ "$1" = "startnbg" ] 然后 start-stop-daemon --start -m --oknodo --pidfile /home/pi/pid/MonoDaemon$ elif [ "$1" = "stop" ] 然后 start-stop-daemon --stop --retry=TERM/30/KILL/5 --pidfile /home/pi/pid/$ else echo Unknown command fi
-
无需论证
ProcessStartInfo startInfo = new ProcessStartInfo() { FileName = "/etc/init.d/mnw stop"};或尝试ProcessStartInfo startInfo = new ProcessStartInfo() { FileName = "/bin/bash", Arguments = "/etc/init.d/mnw stop", };