我使用的框架是.Net 8。
我尝试遵循如何在 C# Mono 中执行 Linux 命令行
中接受的答案这是我的代码:
ProcessStartInfo _processStartInfo = new ProcessStartInfo();
_processStartInfo.FileName = "dmesg | grep tty";
_processStartInfo.UseShellExecute = false;
_processStartInfo.RedirectStandardOutput = true;
Process p = Process.Start(_processStartInfo );
var _result = p.StandardOutput.ReadToEnd();
p.WaitForExit();
p.Close();
我运行代码后,它报告此错误:
Unhandled exception. System.ComponentModel.Win32Exception (2): An error occurred trying to start process 'dmesg | grep tty' with working directory '/home/admin' . No such file or directory
at System.Diagnostics.Process.ForkAndExecProcess(ProcessStartInfo startInfo, String resolvedFilename, String[] argv, String[] envp, String cwd, Boolean setCr edentials, UInt32 userId, UInt32 groupId, UInt32[] groups, Int32& stdinFd, Int32 & stdoutFd, Int32& stderrFd, Boolean usesTerminal, Boolean throwOnNoExec)
at System.Diagnostics.Process.StartCore(ProcessStartInfo startInfo)
at System.Diagnostics.Process.Start(ProcessStartInfo startInfo)
有什么问题吗?