在raspbian上使用单声道执行shell命令(execute shell command with mono on raspbian)

编程入门 行业动态 更新时间:2024-10-28 10:26:12
在raspbian上使用单声道执行shell命令(execute shell command with mono on raspbian)

我试图将我的xbox 360控制器连接到我的树莓派,并使用单声道的c#。 要连接的命令是'sudo xboxdrv'。 如果我直接在树莓派上尝试这个命令,但是当我从单声道控制台应用程序尝试时会出现错误。 我使用的代码是:

var info = new ProcessStartInfo(); info.FileName = "sudo xboxdrv"; info.UseShellExecute = false; info.CreateNoWindow = true; info.RedirectStandardOutput = true; info.RedirectStandardError = true; var p = Process.Start(info); p.WaitForExit(); Console.ReadLine();

我得到的错误是'本机错误=找不到指定的文件'。 我想这与sudo有关,但没有sudo程序就无法工作,如果可能的话,我不想让我的用户root用户。

I'm trying to connect my xbox 360 controller to my raspberry pi, with c# in mono. The command to connect is 'sudo xboxdrv'. This command works if I try it directly on the raspberry pi but it gives errors when I try it from a mono console app. The code I use:

var info = new ProcessStartInfo(); info.FileName = "sudo xboxdrv"; info.UseShellExecute = false; info.CreateNoWindow = true; info.RedirectStandardOutput = true; info.RedirectStandardError = true; var p = Process.Start(info); p.WaitForExit(); Console.ReadLine();

The error I get is 'Native error= Cannot find the specified file'. I suppose it has something to do with the sudo, but without sudo the program can't work, and if possible I don't want to make my user root user.

最满意答案

sudo xboxdrv不是文件名,它是带参数的命令。 sudo是文件名, xboxdrv是参数。

所以你的代码应该是:

var info = new ProcessStartInfo(); info.FileName = "sudo"; info.Arguments = "xboxdrv"; info.UseShellExecute = false; info.CreateNoWindow = true; info.RedirectStandardOutput = true; info.RedirectStandardError = true; var p = Process.Start(info); p.WaitForExit(); Console.ReadLine();

sudo xboxdrv isn't a filename, it is a command with arguments. sudo is the filename, xboxdrv is the argument.

So your code should be:

var info = new ProcessStartInfo(); info.FileName = "sudo"; info.Arguments = "xboxdrv"; info.UseShellExecute = false; info.CreateNoWindow = true; info.RedirectStandardOutput = true; info.RedirectStandardError = true; var p = Process.Start(info); p.WaitForExit(); Console.ReadLine();

更多推荐

本文发布于:2023-07-16 04:00:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1123461.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:单声道   命令   shell   raspbian   command

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!