我试图将我的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();更多推荐
发布评论