Reputation: 171
I am calling a bat file from a perl script.
Since the bat file takes long time for execution, the perl script is not waiting for the bat file to complete and continuing execution from the next line.
Is there a way by which we can suspend the execution of the perl script until the bat file is finished execution and then resume once the bat file is done.
I wrote something like this:
system ("start $bat_file");
print ("Hello");
So it prints hello even before bat file is finished.
Actually what I want to accomplish is:
But as it is not waiting for the bat file to complete, the copy fails because it tries to copy a folder which does not exist as the bat file is still being processed and has not produced the output file.
Note : Time to complete bat file is not fixed and changes everytime.
Upvotes: 1
Views: 748
Reputation: 126732
You need to remove the start
command
Without the /wait
option, start
will create a process and return immediately
But there is no need for start
at all. You can write just
system($bat_file);
to achieve the effect that you're asking for
Upvotes: 9
Reputation: 6960
The problem that you have is the problem with start command
and not with system
When you are using start
command on windows it will start your program but will not wait for ending.
You have to use /wait
after start
In your code it will be :
system ("start /wait $bat_file");
print ("Hello");`
Upvotes: 2