I am encountering a performance problem while executing a bash command from dot-net-core 5.0.
I have n files (.csv) in a specific directory
based on some business rules I write n file_name into a (.txt) file
After finishing I execute a shell command from dot-net-core that reads from the file and execute [mv] command which moves the files that their full names are written in the txt file from a location to another.
The action is performing normally! but!
The issue is that I execute the same process with the same resources (file_name.txt) from dot-net-core it took about 2 minutes to finish while the same code is executed from the shell took 11 seconds!
string source_location = new FileInfo(files.FirstOrDefault()).DirectoryName; string tmp_file_name = Guid.NewGuid().ToString().ToUpper(); string tmp_full_name = Path.Combine(source_location, tmp_file_name) + ".txt"; File.WriteAllLines(tmp_full_name, files); string cmd = $"cat {tmp_full_name} | xargs mv -t {targetFolder}"; string time_now = DateTime.Now.ToString(); Tuple<string, string> result = ShellHelper.Bash(cmd); string time_finish = DateTime.Now.ToString(); string number_of_files = files.Count.ToString(); log.Info(String.Format("\n [START]: {0} \n [END]: {1} \n [RESULT_BASH]: {2} \n [STATE_BASH]: {3} \n [NUMBER_OF_FILES]: {4} -------------- \n", time_now, time_finish, result.Item1, result.Item2, number_of_files)); private static class ShellHelper { public static Tuple<string, string> Bash(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 Tuple.Create(result, process.ExitCode.ToString()); } }
89347-750d00a0-e017-4936-93e1-95d224ebb6e4.txt89348-difference-of-result.txt