Batch File

January 26, 2010 at 05:36:53
Specs: Windows 2000 Pro
Hello,
I am creating a batch file which has two lines of code. The first line launches a 3-D modeling program, Pro/Engineer, and creates a model based on the instructions in the text file, InsSocketFr.txt. The second line creates a text file, flag.txt, which lists the files located in the current directory. Both commands run properly but I would like them to run in sequence. In other words I would like the process of launching the 3-D modeling program and creating the model to complete before the flag.txt text file is created. Below appears the code:

start /wait proe.exe InsSocketFr.txt
dir > flag.txt

I checked the task manager for new processes that occur while computer carries out the command in line 1 and found that an xtop.exe appears while the 3-D program is running and the disappears when the 3-D program closes.

Does anyone know how to make the commands run in sequence instead of synchronously?

Thanks for the help,
TazEngr


See More: Batch File

Report •


#1
January 26, 2010 at 06:50:41
What you coded is exactly what is needed to execute the commands in sequence, i.e. the /wait switch forces the command below Start to wait until proe.exe termination.

So it seems there is nothing wrong.

Are you sure the files proe.exe creates are stored in the batch current directory?


Report •

#2
January 26, 2010 at 07:52:33
oh no. My current directory is the bin directory where proe.exe is located and I am saving the files to a different directory.
Do they have to be the same directory?

Report •

#3
January 26, 2010 at 08:28:10
No, I just want to point out the DIR command issued lists the files stored in the BIN directory (your current one). If you want to list the files created by the proe.exe command after its termination you have to code

dir Folder_Holding_Files > flag.txt

That may be the cause you assume the execution is not sequential, not the structure of the code itself.


Report •

Related Solutions

#4
January 26, 2010 at 08:40:45
Actually I see the creation of the file before the 3-D program even launches.

Report •

#5
January 26, 2010 at 08:43:44
Ah, the old "START" problem.

Here is what happens : the batch comes to the line, holding the START command. It nicely does what asked ...

... BUT, a feature of the START command, is that it splits off the STARTed program. In other words, it's like you suddenly have 2 programs running. One is the initial batchfile, the other is the EXE. They lead a separated life, from the moment START is initiated.

The PROBLEM is that STARTing an EXE, often takes some time. And of course, what happens in the mean time ? The batch script DOES NOT WAIT, it just continues with the next line, whatever that is. And because the DIR command will be MUCH faster than launching the EXE, the DIR will have been completed, before the starting process (the time needed to start a process) has been run through.

In reality, it will often mean that the latter command will be done before the first seems to be done, destroying the sequence.

So, when you understand what happens, you can anticipate onto this. An easy way, is to do this :

start /wait proe.exe InsSocketFr.txt
pause
dir > flag.txt

You here need to WAIT until the EXE is started, THEN press enter in the DOS screen. This solution however, makes your script manual (!). Often, this is not good.

So, instead of PAUSE, a sort of timing feature would be nice. DOS lacks a decent timing command (SLEEP in unix/linux), so you need to abuse another command, be it this one :

start /wait proe.exe InsSocketFr.txt
choice /Ca /T:a,10
dir > flag.txt

This will wait 10 seconds, then continue. You can make it up to 99 seconds. It's not perfect, but behold that the startup of your EXE takes 5 to 10 seconds, you could set it to 15 or 20 seconds, and all will be OK. Apart from the fact it will be slow ... but no other issue.

What you also can do, is be lucky, and know that the EXE is creating a file or a directory, when it has started up completely. This chance is very slim, but if you are lucky, you could do:

start /wait proe.exe InsSocketFr.txt
:loop
if NOT exist C:\createdbytheEXEfile.abc goto loop
dir > flag.txt


Report •

#6
January 26, 2010 at 09:00:43

@tvc

do you know how the switchs modify Start behavior?

/wait just synchronizes the parent and child tasks generated forcing the batch to wait until the child process ends.

Please, vefify carefully what you post as here there are newbees too.

Look at START /? and pay attention CHOICE is not standard in Windows XP.


Report •

#7
January 26, 2010 at 09:43:13
"I checked the task manager for new processes that occur while computer carries out the command in line 1 and found that an xtop.exe appears while the 3-D program is running and the disappears when the 3-D program closes."

setlocal
proe.exe InsSocketFr.txt
:00
for /f %%a in ('tasklist | find /i "xtop.exe "') do set xx=%%a
if "%xx%" neq "" goto :00
dir Folder_Holding_Files > flag.txt

maybe something like this might work, could probly be coded more efficiently



Report •

#8
January 26, 2010 at 11:00:57
Ok I tried to go with the option that makes the batch file wait ten seconds:

start /wait proe.exe InsSocketFr.txt
choice /Ca /T:a,10
dir > flag.txt

However I get this error:
'choice' is not recognized as an internal or external command,
operable program or batch file.

Do I need to create a new batch file to tell it what choice means?


Report •

#9
January 27, 2010 at 02:51:13
> do you know how the switchs modify Start behavior?
>
> /wait just synchronizes the parent and child tasks
> generated forcing the batch to wait until the child process
> ends.
>
> Please, vefify carefully what you post as here there are
> newbees too.
>
> Look at START /?
>

You can try to use the /WAIT parameter, but it'll not always work, unlike the solutions I've proposed. When I propose solutions, I don't start with the ones that work least good, and if I do, I probably put them in the bottom of the list, stating they don't work good.


Report •

#10
January 27, 2010 at 02:54:34
> pay attention CHOICE is not standard in Windows XP
>

..

> However I get this error:
> 'choice' is not recognized as an internal or external
> command,
> operable program or batch file.
>
> Do I need to create a new batch file to tell it what
> choice means?
>

Yes ... CHOICE is not standard Windows ... *sigh*

It was in Windows98 ... anyway ... http://hp.vector.co.jp/authors/VA00...

And even CHOICE is not meant for the job, but it's the best MS can do. If you want a decent program : http://www.sleepcmd.com/


Report •

#11
January 27, 2010 at 03:02:12
> maybe something like this might work, could probly be
> coded more efficiently
>

Yes, but that code is just waiting until the program (the process) has stopped ... not sure that is what he wants. Basically, if the program has ended, it'll not benefit from any actions, since the program does not work, when you run the subsequent code of the main script.


Report •

#12
January 27, 2010 at 04:33:59
Of course, if file InsSocketFr.txt only gets created by means of running the EXE, this would be the file to wait on ... so:

(I removed the WAIT here because you don't want to wait until the program is finished, it's useless here)

start proe.exe InsSocketFr.txt
:loop
if NOT exist InsSocketFr.txt goto loop
sleep 10
dir > flag.txt

But then you may have issue, that it takes time between the CREATION of the file, and the last UPDATE to the file. It can be one (quick) action, but I know lots of programs taking X amounts of seconds to do that. So, either build in an additional sleep (or whatever you find on the net that is working), wait long enough, THEN continue.
Or, if you know that the file is only OK if it stores a given keyword, you could look for that, and only continue when that is OK.

Try this, if you feel the urge:

start /wait proe.exe InsSocketFr.txt
:loop
echo Waiting for InsSocketFr.txt
if NOT exist InsSocketFr.txt goto loop
:showfile
cls
type InsSocketFr.txt
goto :showfile


Report •

#13
January 27, 2010 at 05:13:09
tvc - i think you've got it backwards:
"The first line launches a 3-D modeling program, Pro/Engineer, and creates a model based on the instructions in the text file, InsSocketFr.txt."
ie: InsSocketFr.txt exists prior to execution of pro.exe and acts as a "script" input-feed to pro.exe.
I believe he's looking for the output file(s) from pro.exe which he is using "DIR" to look for. i think.
hence the reason he wants to wait till pro.exe is finished before doing DIR.
IVO's observation still holds, that the correct directory needs to be analyzed, not necessarily the CD (or pwd).

"oh no. My current directory is the bin directory where proe.exe is located and I am saving the files to a different directory."


Report •

#14
January 27, 2010 at 07:03:26
Possibly ... Taz will point out what he needs, we can debate as much as we want. I think he DOES NOT want to wait until he finishes his GUI program, before he creates the file "flag.txt". If he would, he might as well first create the file, THEN start the GUI program.

The directory thing you specify is indeed important. I'm first assuming all is happening in the same directory.


Report •

#15
January 27, 2010 at 07:17:26
Ok great I actually ended up going with the loop method that checks for the file that the line

"start /wait proe.exe InsSocketFr.txt"

and it worked out well. Note that InsSocketFr.txt is a text file with instructions to create a model. I am making a large number of similar models by changing a couple of parameters in InsSocketFr.txt and placing the command in a For Loop. Here is the batch file that I ultimately used. Note that I just used the command dir > flag.txt just to prove the holding method. It could have been anything like a display text box or something.

cd C:\program files\proeWildfire 3.0\bin
start /wait proe.exe InsSocketFr.txt
cd C:\Documents and Settings\motaza\proe\Parts\InsSocFrs
:loop
if Not exist %1.prt.1 goto loop
dir > flag.txt


Thanks everyone for your input. I am going to call this batch file from Visual Basic and will update on how that goes.

TazEngr


Report •

#16
January 28, 2010 at 02:58:30
And he is running the loop, while the GUI is running, right ?

Report •

Ask Question