bash C#在linux中执行终端命令
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/23679283/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
C# execute a terminal command in linux
提问by user3218392
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 :
我希望我的 c# 应用程序(我在树莓派上执行)在启动时运行 bash 脚本......
基本上:脚本位于/etc/init.d
并命名为mnw
. 我希望每当我的 c# 应用程序启动时,它都应该执行 mnw 脚本的一部分。
如果它是在终端中编写的,它将如下所示:
cd /etc/init.d
./mnw stop
I want this to happen right at the start of public static void Main()
, I've been trying
我希望这在开始时发生public static void Main()
,我一直在尝试
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?
但它说停止是一个意想不到的论点,有什么想法吗?
采纳答案by flindeberg
I have never used ProcessStartInfo
on Mono / Linux, but have you tried calling via bash?
我从未ProcessStartInfo
在 Mono / Linux 上使用过,但是您是否尝试过通过 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
?
此外,可执行位没有问题mnw
?