Problem:
1. Load a shell to running a commands, then, some strings are output
2. Validate the string contain special keywords
Like:
i want to check whether complianceserver is running or not.
Solution:
Regular
How?
1. Load system.text.regularexpression into namespace in c#
2. Get the results from shell
3. Set a regular pattern
4. Use Regex.ismatch( ) to check result.
Codes:
String ResultsStrings = myProcess.StandardOutput.Readtoend( );
String RegexPattern = "RUNNING";
/query/
Regex.Ismatch( ResultsStraings, RegexPattern, RegexOptions.Multiline);
If results contain, it will return TRUE, else return FALSE.
During the testing, i meet fail many times.
So, i doubt the Pattern is correct.
So, how to check this?
In Windows, We can use "findstr" command and in Linux/Unix, we can use "grep" to query first.
If match, we will get content of the line the matched string is in.
Format:
Findstr/grep "regexpattern" "*.txt".