i am using dotnet-core 1.1. centos bash
any way to run the grep or wget and retrieve the result?
like cmd in windows, but i need grep realtime log files
System.Diagnostics.Process.Start("notepad.exe")
This method is quite easy to run a bash script, and all of them are quite simple. We just need to type in “source” before the file/script name with an extension. In a terminal, run the following code by replacing the filename with your bash script filename. The script will simply get executed after “sourcing” the file.
The shebang, #!/bin/bash when used in scripts is used to instruct the operating system to use bash as a command interpreter. Each of the systems has its own shells which the system will use to execute its own system scripts.
The dotnet run command provides a convenient option to run your application from the source code with one command. It's useful for fast iterative development from the command line. The command depends on the dotnet build command to build the code.
You can start a process to grep and retrieve the result, you can refer the following code.
System.Diagnostics.ProcessStartInfo procStartInfo;
procStartInfo = new System.Diagnostics.ProcessStartInfo("/bin/bash", "-c \"cat myfile.log | grep -a 'dump f'\"");
procStartInfo.RedirectStandardOutput = true;
procStartInfo.RedirectStandardError = true;
procStartInfo.UseShellExecute = false;
procStartInfo.CreateNoWindow = true;
System.Diagnostics.Process proc = new System.Diagnostics.Process();
proc.StartInfo = procStartInfo;
proc.Start();
// Get the output into a string
result = proc.StandardOutput.ReadToEnd();
I believe System.Diagnostics.Process.Start(..) which is in the System.Diagnostics.Process nuget package can take a ProcessStartInfo type as one of the overloads. That type has the following properties when set to true will redirect the logs to a stream in the Process type that is returned by System.Diagnostics.Process
var proc = System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo() {
RedirectStandardOutput = true,
RedirectStandardInput = true,
RedirectStandardError = true
} );
proc.StandardError //stream with stderror
proc.StandardInput //stream with stdin
proc.StandardOutput //stream with stdout
Shameless plug, I also made a package that easily abstracts opening things on mac/win/linux basically abstracting xdg-open (ubuntu), open (mac), cmd.exe (win) so you don't have to think about it
https://github.com/TerribleDev/Opener.Net
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With