Interactive shell commands now work

The code for this was written by gpt3
This commit is contained in:
FUH22860 2022-12-06 16:53:10 +01:00
parent ebf5b9e304
commit ed5286435a
2 changed files with 48 additions and 9 deletions

View File

@ -2,5 +2,7 @@
static void Main(string[] args) { static void Main(string[] args) {
string result = Update.copyEverthingToBackup(); string result = Update.copyEverthingToBackup();
Console.WriteLine(result); Console.WriteLine(result);
Update.startUpdate();
} }
} }

View File

@ -20,23 +20,60 @@ public class Update {
processStartInfo.FileName = @"yay"; processStartInfo.FileName = @"yay";
processStartInfo.WorkingDirectory = getHomePath(); processStartInfo.WorkingDirectory = getHomePath();
//processStartInfo.Arguments = "--color"; //processStartInfo.Arguments = "--color";
processStartInfo.RedirectStandardOutput = false; processStartInfo.RedirectStandardOutput = true;
processStartInfo.RedirectStandardError = false; processStartInfo.RedirectStandardError = true;
processStartInfo.UseShellExecute = true; processStartInfo.UseShellExecute = false;
process.StartInfo = processStartInfo; process.StartInfo = processStartInfo;
process.Start(); process.Start();
process.StandardInput.WriteLine(" "); // Read the output of the "yay" command
string output = process.StandardOutput.ReadLine();
string error = process.StandardError.ReadToEnd();
process.WaitForExit();
//shellStream.WriteLine("passwd fadwa"); Console.WriteLine(output);
//shellStream.Expect("Enter new password:"); Console.WriteLine(error);
//shellStream.WriteLine("fadwa");
//shellStream.Expect("Retype new password:");
//shellStream.WriteLine("fadwa");
} }
// using System;
// using System.Diagnostics;
// namespace UpdateLinux
// {
// class Program
// {
// static void Main(string[] args)
// {
// Console.WriteLine("Updating Linux system...");
// // Use the Process class to run the "apt-get update" command
// var process = new Process()
// {
// StartInfo = new ProcessStartInfo
// {
// FileName = "yay",
// UseShellExecute = false,
// RedirectStandardOutput = true,
// RedirectStandardError = true
// }
// };
// process.Start();
// // Read the output of the "apt-get update" command
// string output = process.StandardOutput.ReadToEnd();
// string error = process.StandardError.ReadToEnd();
// process.WaitForExit();
// Console.WriteLine(output);
// Console.WriteLine(error);
// Console.WriteLine("Linux system updated!");
// }
// }
// }
public static string copyEverthingToBackup() { public static string copyEverthingToBackup() {
string fileName = "fstab"; string fileName = "fstab";
string sourcePath = @"/etc/"; string sourcePath = @"/etc/";