• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 44
  • Last Modified:

Breaking 2 exes in a command line

I have 2 exes to execute in a command line which purpose is to write to a d

\\fileA\program\Task1.exe
??
\\fileA\program\Task2.exe


The purpose of each task is to insert data into a table in 2 different servers.
For some strange thing that happened,Task1.exe has not completed the job yet and it hanged up. Meanwhile
Task2.exe also executed slowing the task. These took very long to finish.
I'd like to create a command line to check if Task1 finish without error before firing the Task2.exe.
0
zachvaldez
Asked:
zachvaldez
  • 4
  • 3
  • 2
1 Solution
 
it_saigeDeveloperCommented:
You can see if the task is still running before proceeding (described in a previous EE_PAQ - https:/Q_26733769.html); e.g. -
@ECHO OFF
START "" "\\fileA\program\Task1.exe"

:LOOP
TASKLIST | find /I "Task1.exe" > nul:
IF NOT errorlevel 1 goto :LOOP

START "" "\\fileA\program\Task2.exe"

:LOOP2
TASKLIST | find /I "Task2.exe" > nul:
IF NOT errorlevel 1 goto :LOOP2

Open in new window


-saige-
1
 
zachvaldezAuthor Commented:
Is it possible to display a message if completed at the end?
0
 
it_saigeDeveloperCommented:
Sure thing just add something like:
@ECHO OFF
START "" "\\fileA\program\Task1.exe"

:LOOP
TASKLIST | find /I "Task1.exe" > nul:
IF NOT errorlevel 1 goto :LOOP

START "" "\\fileA\program\Task2.exe"

:LOOP2
TASKLIST | find /I "Task2.exe" > nul:
IF NOT errorlevel 1 goto :LOOP2

ECHO "Tasks completed!!!"

Open in new window


-saige-
0
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
zachvaldezAuthor Commented:
what does these lines mean? Thanks

:LOOP
TASKLIST | find /I "Task1.exe" > nul:
IF NOT errorlevel 1 goto :LOOP
0
 
it_saigeDeveloperCommented:
:LOOP - represents a label named LOOP.  It's basically a marker that you can use to *skip* to by way of a CALL or GOTO instruction.

TASKLIST - is a dos command that is used to "display all running applications and services with their Process ID (PID)", you can read more about TASKLIST here and here.

The | (or pipe) is a command redirection operator; the pipe is used to redirect the output of the TASKLIST command to the FIND command.  The FIND command has a paremeter /I which means that the search is not case-sensitive.  We are looking specifically for "Task1.exe".  

When we find "Task1.exe" we use the > sign to redirect both the std and error outputs to the null device.  With the output redirected we look at the errorlevel to determine if the call was successful or not.  If the process was found, we goto the LOOP label, otherwise we execute the next instruction.

Proof of concept:
@ECHO OFF
TASKLIST | FIND /I "NOTEPAD.EXE" > nul:
IF ERRORLEVEL 1 ( 
ECHO NOTEPAD WAS NOT FOUND!!!
GOTO EOF
) ELSE ( ECHO NOTEPAD WAS FOUND )
:EOF

Open in new window

Produces the following output when notepad is running:Capture.PNGAnd this output when notepad is not running:Capture.PNG
-saige-
1
 
Shaun VermaakTechnical Specialist/DeveloperCommented:
ECHO OFF 
START /WAIT \\fileA\program\Task1.exe
START /WAIT \\fileA\program\Task2.exe
ECHO "Tasks completed!!!"

Open in new window

0
 
zachvaldezAuthor Commented:
Sorry for long time to response.
When Task1.exe, Can it check if an input file exist in C:\Assign folder.  and when it finishes delete the file.
0
 
Shaun VermaakTechnical Specialist/DeveloperCommented:
When Task1.exe, Can it check if an input file exist in C:\Assign folder
Yes, and do what when it exist/do not exist?
0
 
zachvaldezAuthor Commented:
what's the command line? had to hard code the path
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

  • 4
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now