LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Restart a labview application using a .bat file

Solved!
Go to solution

I have a simple labview application to add numbers and after adding number the application asks whether you want to do it again or end the program. If you click do it again then the application closes and start again. This application is for me to learn how to restart another application. The important part is the restarting the application. So for that, I create a bat file. The bat file is created by the application itself and the program in the bat file is written by using a write to text file and save it as . bat and then after creating the .bat file, i run it by using system exec.vi. Now I run the program and then the .exe application is run and as expected the application is closed by the .exe application, but the restart is not done. The application doesnt restart again. I dont another thing when i just start the application and dont do the addition so that the question to restart application will not be asked. It will just keep running without doing anything. At this time, I just ran the .bat file that was created earlier and when I run that, then the labview application will be stopped and started again. So when I run the .bat application seperately it works fine by stopping and starting the application. But when I run the .bat file from within the labview application then only stopping the program happens, it doesnt restart. So what is the problem. I have attached the zipped folder containg everything including the labview project, application and the .bat file. Kindly go through it and help me. Thank you.

 

Govind

0 Kudos
Message 1 of 14
(2,350 Views)

A batch file (any process) that is run by a process might be terminated if the creating process is terminated.

 

A LabVIEW application that is already (still) running, won't be started again. So if a LabVIEW exe starts itself and then stops, there will be no new executable.**

 


@govindsankar wrote:

This application is for me to learn how to restart another application.


What you are doing now is harder... You're not restarting another application, you're trying to make an application restart itself.

 

 

** By default. You can put allowmultipleinstances = TRUE in the exe's ini file, in it's main section.

0 Kudos
Message 2 of 14
(2,314 Views)

This is the program I wrote in the .bat file

taskkill /f /im LearnBatV1.0.0.exe
timeout /t 1
start " " "K:\POST\Govind\My Actual Work\LearnBat\LearnBatV1.0.0.exe"
exit. 

I didnt understand by what you meant by multiple instance = true. I am tryng to learn .bat programming

0 Kudos
Message 3 of 14
(2,302 Views)

Either the .bat process is killed because the caller is killed, or the 2nd process isn't started because it is still running.

 

Note that when you call command exec, wait until completion is set to true. So LV keeps handles to the .bat process, and when the process kills LabVIEW, the .bat process itself is killed as well. You might try wiring a false to that input.

 

If you add allowmultipleinstances=TRUE to the ini file of the executable, the exe doesn't need to be closed. Opening it a 2nd time will simply open a 2nd instance. That will simplify the problem.

0 Kudos
Message 4 of 14
(2,288 Views)

I added the line (LearnBatV1.0.0.exe):allowmultipleinstances=TRUE to the last line of the .ini file. But it still doesnt work. Application gets shut down and closed but still it is not restarted.

0 Kudos
Message 5 of 14
(2,284 Views)

Do you have "Wait until completion=True" on System Exec?

0 Kudos
Message 6 of 14
(2,279 Views)

@BertMcMahan wrote:

Do you have "Wait until completion=True" on System Exec?


Yes, it's unwired, so default true.

0 Kudos
Message 7 of 14
(2,274 Views)

Not sure if I'd be sacrificing elegance for simplicity, but what I would do is make a "middleman" executable to be called when you want the app to restart itself.

 

When you want the app to restart itself, call the middleman exe using system exec and then shutdown the app. All the middleman exe would be: a two button dialog where you can either choose to restart the app or cancel. Choosing to restart the app would then just use system exec once again to call the original app.

 

You could even theoretically make a "general app self-restart helper exe" that can somehow take in an app name and be used to self-restart any app.

 

One other thought I had: with the multiple instances as True in your .ini, call a second instance of your executable (using system exec) and then close the first instance. Haven't tried it myself but I feel like on the front end it would barely be noticeable.

Redhawk
Test Engineer at Moog Inc.

Saying "Thanks that fixed it" or "Thanks that answers my question" and not giving a Kudo or Marked Solution, is like telling your waiter they did a great job and not leaving a tip. Please, tip your waiters.

0 Kudos
Message 8 of 14
(2,267 Views)

Yes it is wired to be true

0 Kudos
Message 9 of 14
(2,263 Views)
Solution
Accepted by topic author govindsankar

I made this a long time ago.  Just drop it on your BD.

"If you weren't supposed to push it, it wouldn't be a button."
Message 10 of 14
(2,241 Views)