LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Closing the command window after running .bat file using System Exec VI

Hello All:

 

I am running LV 2023 32-bit and I am having trouble closing the command window in LabVIEW using the System Exec VI.

 

Please see the attached pic for my settings.

 

When I double click the .bat file, after the file completes the window disappears.  I opened up the .bat file with Notepad+ and there is an exit command at the end of the program.   When I run it in LV, the window remains open and I have to type "exit" in the command window.

 

I found this knowledgebase article:

https://knowledge.ni.com/KnowledgeArticleDetails?id=kA00Z000000P7lUSAS&l=en-US

 

In the article, solution number 2 states " use the command .com program with the /C flag".  I've tried different combinations to no avail.  Can somebody help me with this?

 

Thank you

 

0 Kudos
Message 1 of 6
(1,086 Views)

If you would lake to have command prompt closed when called program completed, may be more simple solution will be suitable for you:

snippt-cmd.png

0 Kudos
Message 2 of 6
(1,053 Views)

Typing the following at the prompt will close the Command Window:

  • Exit

Make a .Bat file using the Start for your LabVIEW program followed on the last line with the Exit command.

Help the Community (and future reviewers) by marking posts as follows:
If it helped - KUDOS
If it answers the issue - SOLUTION
0 Kudos
Message 3 of 6
(1,001 Views)

Here is the .bat file with all the exit commands in red.  As stated, when I double click on this .bat file everything works great, the command window closes.  It's when I use the System Exec VI, I need to type "exit" into the command window to get it to close.  (I have wait until close set to TRUE)

 

@echo off
setlocal
setlocal ENABLEDELAYEDEXPANSION
 
REM Path to this batch script
set UNIFLASH_PATH=%~dp0
 
REM Path to DebugServer folder
set DEBUGSERVER_ROOT=%~dp0ccs_base\DebugServer\
 
set MODE=flash
set EXECUTABLE="!DEBUGSERVER_ROOT!bin\DSLite"
 
set GENERATED_COMMAND=-c user_files/configs/f28234.ccxml -l user_files/settings/generated.ufsettings -s VerifyAfterProgramLoad="No verification" -e -f -v "user_files/images/9675-1010-000 test2 20KHZ fan.out" 
set ADDITIONALS=
 
REM list available modes
if "%1"=="--listMode" (
echo.
 
echo Usage: dslite --mode ^<mode^> arg
echo.
 
echo Available Modes for UniFlash CLI:
echo   * flash [default] - on-chip flash programming
echo   * memory          - export memory to a file
echo   * load            - simple loader [use default options]
echo   * serial          - serial flash programming
echo   * noConnectFlash  - bypasses connect sequence during flash; for programming a blank CC23xx device
if exist !DEBUGSERVER_ROOT!drivers\MSP430Flasher.exe (
echo   * mspflasher      - support MSPFlasher command line parameters [deprecated]
)
 
exit /b 0
)
 
REM no parameters given, use the default generated command
if "%1" EQU "" (
echo Executing default command:
echo ^> dslite --mode !MODE! !GENERATED_COMMAND! !ADDITIONALS!
echo.
 
CMD /S /C "%EXECUTABLE% !MODE! !GENERATED_COMMAND! !ADDITIONALS!"
exit /b !errorlevel!
)
 
REM user options parsing
set USEROPTIONS=%*
 
REM user options without the --mode
set "_args=%*"
set "_args=!_args:*%1 =!"
set "_args=!_args:*%2 =!"
 
if "%3"=="" (
set USEROPTIONS2=
) else (
set USEROPTIONS2=!_args!
)
 
REM custom mode from users
if "%1" EQU "--mode" (
set MODE=%2
set USEROPTIONS=!USEROPTIONS2!
)
 
REM default user options if none given
if "!USEROPTIONS!" EQU "" (
set USEROPTIONS=-h
)
 
REM mspflasher support
if "%MODE%" EQU "mspflasher" (
set EXECUTABLE=!DEBUGSERVER_ROOT!drivers\MSP430Flasher.exe
set MODE=
)
 
REM execute with given user parameters
echo Executing the following command:
if "!MODE!" EQU "" (
echo ^> !EXECUTABLE! !USEROPTIONS! !ADDITIONALS!
) else (
echo ^> !EXECUTABLE! !MODE! !USEROPTIONS! !ADDITIONALS!
)
echo.
 
echo.
 
CMD /S /C "%EXECUTABLE% !MODE! !USEROPTIONS! !ADDITIONALS!"
exit /b !errorlevel!

 

0 Kudos
Message 4 of 6
(945 Views)

Hello All:

 

I found a thread where somebody else had the same issue.

 

https://forums.ni.com/t5/LabVIEW/CMD-EXE-Output-Not-Showing-up/m-p/729103

 

Here is an excerpt from the author

 

"Long story short, the only feasible way I found to achieve the desired behavior is this:

 

Run System exec.vi with "cmd /c start batchfile.bat"

This allows you to view the batchfile's output (live) while also waiting for its completion in the labview code. The only drawback I see is that the terminal does not exit automatically when the batchfile finishes. To circumvent this issue just put an "exit" command at the end of your batchfile."

 

However, I DO have an exit at the end of my .bat file and the command window is still there 🤔

 

 

 

 

0 Kudos
Message 5 of 6
(974 Views)

@geekodude wrote:

 

Run System exec.vi with "cmd /c start batchfile.bat"

This allows you to view the batchfile's output (live)

...

I DO have an exit at the end of my .bat file and the command window is still there 🤔

 


Ah, OK, you would like to see live output. Then its corect, but you have to put exit at the end of called batch file, then it works, at least for me:

 

snippet2.png

0 Kudos
Message 6 of 6
(950 Views)