Showing results for 
Search instead for 
Did you mean: 

System exec batch file run problems

I need help with running a batch file using a System Exec.VI.   When I run my application with wait until completion enabled(TRUE) I get a blank screen but when I run it disabled I get a proper response.   In my case I need to be able to see the command window and I need LabView to wait till this window is closed until LabView executes the rest of the code.  Any ideas on how to fix this?



Download All
Message 1 of 10

Also when I change program to the following I only get a partial screen without .bat file beeing executed.  And playing with the wait flag gives oposite results  where if TRUE the command window only appears for the brief moment and goes away.

SysExec Test1.PNG



0 Kudos
Message 2 of 10

The help for the sysexec function says the following:


sysexec help.PNG


So I think you have misunderstood the functionality of that flag.  If you don't want the rest of your LabVIEW code to execute until the sysexec is done, use the error wire output from the sysexec function to dictate the dataflow.


I've used the sysexec function to run batch files which launched other programs, with no problems.



0 Kudos
Message 3 of 10

I tried this and it looks like the error output gets executed even before I have a chance to close the command window.  This defeats the purpose since in the example shown below user message gets executed before system exec is finished.  If I make the Wait Until Completion flag TRUE than it waits till I close the window but my command window is blank not displaying any commands included in the .bat file.

SysExec Test 2.PNG

0 Kudos
Message 4 of 10

Very strange.  Not having your batch file, I am unable to run your snippet in any kind of useful way.  In the picture I posted, my batch file runs (goes onto a network, selects and downloads a file, then calls another program, which programs a chip) and then the sysexec window closes, previous to the code inside the case structure executing.


Unfortunately I don't have time to delve into this right at present, but will try to get back to it tomorrow unless someone else beats me to it!  I'm sure that there are many folks out there with a greater understanding of the sysexec function than I possess, and we would be grateful to hear from them.  🙂

0 Kudos
Message 5 of 10

Attached is the batch file and other files that are required to run it.   The FlashLoader.exe will try to upload the Test.hex file into microcontroller connected to a specific com port specified by --pn ?.   All you need to do is change the .bat file to point to one of your existing com ports.  You don't need to have the actual device, it will still run and give you a warning that the device has not been detected.   Thank you

0 Kudos
Message 6 of 10

Hi there,


I did not run your batch file, since I have a thing against running unknown executables on my machine.  (Long ago, when I was younger and more foolish, I learned my lesson in that regard.)  What I did instead was take a look at your batch file, and compare it with mine.


It seems that there is a difference in the way the two of us write batch files, which led to my giving you erroneous advice earlier.  My apologies.  I believe I now have a better understanding of how sysexec works, so thank you!


When I run a batch file to launch an application, my batch file uses a "start /wait" command to launch the application.  That forces the batch file to wait until the application I've launched has finished running, before the next command line in the batch file is executed.  The sysexec won't finish executing until the batch file has finished executing, thus the reason that the code inside the case structure doesn't execute until the application I've called has finished executing.


Your batch file launches the application and immediately finishes, allowing the sysexec function to finish executing as well.  When the sysexec finishes executing, the rest of your code can execute.


May I suggest you use a "start /wait" command to launch your application and see how that works?  I wrote some dummy code (and a dummy batch file) to test it out and using the "start /wait" command inside my batch file definitely caused LabVIEW to pause until the batch file was finished executing.


I use an "exit" command at the end of my batch files, too, but it's probably not necessary.


Let me know how it goes.


0 Kudos
Message 7 of 10

This does not seem to work.  START command just oppens additional window but the rest is the same.  Where do you put the wait statement?

In the .bat file or in Labview?

0 Kudos
Message 8 of 10

The start /wait command goes in the batch file.


echo on


start /wait "C:\Program Files (x86)\STMicroelectronics\Software\Flash Loader Demonstrator\STMFlashLoader.exe" -c --pn 4 --br 115200 -i STM32_High-density_256K -e --all -d --fn "C:\Praca\LABVIEWPROJECTS\Test Board Suite - Labview 2011\Flash Loader\Test.hex"



Does that help?


Here's an example for you (written in 8.5, since that's the version my client is using and it's what I happen to have open on my machine at present).  It's a LabVIEW program which calls the sysexec to launch another LabVIEW application (an exe), and displays a message to the user after the exe has been terminated and its front panel closed.  The LabVIEW project includes the VI which calls the sysexec, the batch file, and the executable which the batch file launches.


Note that the syntax for the path to the executable is a little different -- it's a relative path, since in this case the called application resides in the same parent folder as the batch file.  Note also that if you're going to do it that way, you can't have any blank spaces anywhere in your file path, as they confuse the batch file.

0 Kudos
Message 9 of 10

A little more help for you, about the start /wait command, proper syntax, how to use it, etc.


start wait cmd info.PNG

0 Kudos
Message 10 of 10