Read CMD Window for specific string?

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
SIMMS7400
Posts: 546
Joined: 07 Jan 2016 07:47

Read CMD Window for specific string?

#1 Post by SIMMS7400 » 30 Apr 2017 17:18

Hi Folks -

Happy Sunday!

There are a few services I start that require the CMD Window stay open. With that said, I need to wait until a certain string is displayed on screen before proceeding to the next step. I'm building a script to automate this process so I was wondering if there was a way to read a CMD for a specific string?

The string is : <Server started in RUNNING mode>

I can start the CMD with a specific title if that helps...

Thank you!

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Read CMD Window for specific string?

#2 Post by aGerman » 30 Apr 2017 17:32

The message certainly comes from a command line utility that you run in the batch file. You could run it in a FOR /F loop to process its output or you can redirect its output to a file that you can observe.

Steffen

SIMMS7400
Posts: 546
Joined: 07 Jan 2016 07:47

Re: Read CMD Window for specific string?

#3 Post by SIMMS7400 » 01 May 2017 01:15

Thank you, Steffen.

What I will is FOR loop as when I try to direct the following into a log file, it doesn't work:

Code: Select all

start "path\script.cmd" >>%LOGFILE%


THanks!

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Read CMD Window for specific string?

#4 Post by aGerman » 01 May 2017 04:39

The START command runs your script asynchronously in a new cmd process. That means after the START command was executed the parent batch process immediatelly resumes with the next comand without waiting for the child process (or any of its output). You have to write your log file from within the child process. You may observe the content of this file from within the parent process. But that sounds all overcomplicated to me and indicates a general problem with the design of your code.

Steffen

Post Reply