Loading

.NetCore修改Linux系统时间

public static string BashCommand(string cmd)
        {
            var escapedArgs = cmd.Replace("\"", "\\\"");

            var process = new Process()
            {
                StartInfo = new ProcessStartInfo
                {
                    FileName = "/bin/bash",
                    Arguments = $"-c \"{escapedArgs}\"",
                    RedirectStandardOutput = true,
                    UseShellExecute = false,
                    CreateNoWindow = true,
                }
            };
            process.Start();
            string result = process.StandardOutput.ReadToEnd();
            process.WaitForExit();
            return result;
        }

调用: BashCommand("date --set="2020-01-01 00:00:00"");

posted @ 2023-03-08 17:34  Stay627  阅读(78)  评论(0编辑  收藏  举报