I have a C program which after running makes an executable file (named exec.exe for reference). This executable opens a .txt file and writes some data into it.
Now, I want to give command the run this executable from Labview. I am using system exec.vi to do this. Though separately I am able to open notepad and other system executables using this VI. But when I give the path for my .exe file, the desired .txt file is not being generated.
I am under the impression that System exec.vi does exactly what we execute on command prompt, if I precede it with "cmd /c".
I have attached the example VI and C program.
Solved! Go to Solution.
In your example you're not specifying the working directory (i.e., directory in which your executable is located) for your system exec call. Try specifying that and see if it works.
Even after specifying "working directory" its not working. It now throws an error with error code 267.
This system exec VI is working fine If I run any other C made .exe (a console output type exe and not the type which creates any .txt file). Seems like the problem is with the type of .exe which creates a file (a .txt in this case).
Also if I am not specifying "Working directory" there is no error but after running the VI it seems like it opens the command prompt then it vanishes very fast. But since there is no .txt file being created in the directory, I am assuming system exec VI is not executing the .exe file.
I will further simplify the problem with an attached snapshot.
I have two .exe files (namely a.exe and exec.exe) in a directory, whose path I have specified in the "working directory" of the system exec VI.
One is working (the a.exe which just outputs "Testing" on console).
The other exec.exe (which is supposed to create a .txt file with some random text written in it) is not working. And by "not working" I mean the .txt file is not being created. If I run that executable in command prompt separately, the desired file is being created.
Is system Exec VI not supposed to run the second type of exe?
It may be running but write access could be getting blocked. Can you insert a "pause" in the cmd input so that the window doesn't quickly close to see if there is anything useful there?
Maybe try opening the LabVIEW IDE with "run as admin" to see if that makes a difference:
May be some useful info here, as well:
Batch file option may work:
Could also attempt using System Exec to call Powershell to call your C exe:
cmd /c %SystemRoot%\sysnative\WindowsPowerShell\v1.0\powershell.exe -file “path to file.exe”
NOTE: Check Powershell execution policy: “get-executionpolicy”. Probably needs to be either Unrestricted or RemoteSigned.
After inserting a "pause" in cmd input by "cmd /k" I am getting "C:\>" being displayed (the specified working directory).
I got the idea from here, so now instead of just specifying "C:\" in "working directory" I specified the complete path to the executable. After doing this it is working and file is getting created.
Though my work is done, I still don't get it how the other .exe's are working even after specifying only "C:\" and not the complete path.
The operating system has a number of paths it will look in if you pass it an executable name without specifying a full path. I'm assuming that the other exes you've tried are in a 'standard' location like C:\Windows\System32
If your executable is built somewhere else, Windows won't know where to find it without specifying the full path