Detect cmd script

I run a script/command in cmd.exe of windows and need to detect if it has finished running. how i can do that? i tried using ‘Use Application’ and under that ‘Get Text’ to see if i get back the prompt. but when i select ‘Indicate Target’ for Get Text, i am unable to select cmd.Use Application already registered the cmd.exe but Get Text doesnt do. Is there any way to solve this or some other workaround to detect running command is finished?

@zeesh19791

May be you can write some data to a file or so when ita successful and read the data from
There…

You might not be able tos py cmd directly and it is not recommended also

Cheers

That is a very clever and practical trick. in my case i am running a teradata script and there is no way to write to a text file as u suggested. there are teradata sql commands in that script. so i need to see when i get back the prompt

@zeesh19791

After your teradata has run…use a line to write success to a file…then verify that…if failed
It wont have that line …you have to modify the batch script accordingly

Cheers

your response gave me a nice idea.
i created a batch file in which 1st command runs the teradata script file then 2nd command writes a ‘done’ to text file. in UiPath i added Repeat Number of Times with 9999 as value, read the text file and if file contains done then break else continue…

fastload < D:\UiPath\TearaData-Frontline\Teradata-Frontline\frontcomm_fwa.sql
@echo off
echo done > out.txt

what u think?
do we have While loop in studiox?that is more efficient to detect if text file got ‘done’

i implemented this but it looks like Repeat Number of Times finishes 9999 very quickly because it does wait for sometime but then after few seconds it finishes because else is making it continue until it reaches 9999

@zeesh19791

Thats a good idea…you can add a delay inside loop so as to make it slow…if needed…

Cheers

but that is not efficient. the teradata script may take variable time to finish. today i put delay of 30sec for each iteration with 9999 repetitions, tomorrow this whole duration is not sufficient. there has to something like While loop…to continue until there is something in the file

@zeesh19791

But any time you need to include a max iteration or so…because you cant leave an infinite loop…you can varaiblize the loop counter or the delay or both and can send them as you need whenever needed

Cheers

it wont be an infinite loop technically. as soon as the file is generated with specific text, it will terminate. so,
if(text found):
break
else
continue

@zeesh19791

For some reason if the query breaks or if file is not created then its an infinite loop itself right

cheers

Rather than polling the cmd window to see if it finished, it would be better to call cmd directly. A good way to do this is to use the Invoke Powershell activity. That activity would finish whenever the cmd command finishes.

To do this, the format to use is:
cmd.exe \c "your cmd command here"

In this example, I’m running the cmd command dir and writing it to a text file: