سؤال

I have a text file that is generated and it needs to be verified with a program run from the command prompt. I am trying to build a powershell script that will run the command and tell me if the text file is successful(no errors). When the command is run it only displays the output on the screen as below.

There were 0 warning, 0 fatal, and 0 system errors.

Please press Enter key to quit the program.

I am currently using the the below command to give me this output.

Start-Process "C:\Program Files (x86)\file\file.exe" "C:\abc.txt" -NoNewWindow

I need to read the output on the screen and determine if the result is successful via a string match(true/false)

Any help/ideas is much appreciated

هل كانت مفيدة؟

المحلول

Use Select-String:

$pattern = 'There were 0 warning, 0 fatal, and 0 system errors.'

... | Select-String $pattern -SimpleMatch -Quiet
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top