C# execute a terminal command in linux

我的未来我决定 提交于 2020-01-24 18:52:57

问题


I want my c# application (which I execute on a raspberry pi) to run a bash script whenever it starts..
basically : the script is located in /etc/init.d and is named mnw. I want whenever my c# application starts, it should execute a part of the mnw script.
If it was written it in the terminal would look like :

cd /etc/init.d
./mnw stop

I want this to happen right at the start of public static void Main(), I've been trying

ProcessStartInfo startInfo = new ProcessStartInfo() { FileName = "/dev/init.d/./mnw", Arguments = "stop", }; 
Process proc = new Process() { StartInfo = startInfo, };
proc.Start();

but it says that stop is a unexpected argument, any ideas?


回答1:


I have never used ProcessStartInfo on Mono / Linux, but have you tried calling via bash?

ProcessStartInfo startInfo = new ProcessStartInfo() { FileName = "/bin/bash", Arguments = "/dev/init.d/mnw stop", }; 
Process proc = new Process() { StartInfo = startInfo, };
proc.Start();

Also, there is no issues with the executable bit on mnw?



来源:https://stackoverflow.com/questions/23679283/c-sharp-execute-a-terminal-command-in-linux

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!