LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

System Exec VI is not generating .txt file.

Solved!
Go to solution
Highlighted

Hi,

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.

Download All
0 Kudos
Message 1 of 7
(290 Views)

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.

0 Kudos
Message 2 of 7
(251 Views)
Highlighted

Hi,

Even after specifying "working directory" its not working. It now throws an error with error code 267.

 

 

P.S.

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.

0 Kudos
Message 3 of 7
(188 Views)
Highlighted

Hi,

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?

0 Kudos
Message 4 of 7
(179 Views)
Highlighted
Solution
Accepted by rashp8

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:

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

 

May be some useful info here, as well:

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

 

Batch file option may work:

https://forums.ni.com/t5/LabVIEW/Run-command-prompt-as-administrator-using-system-exec-vi/td-p/29060...

 

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.

Message 5 of 7
(165 Views)
Highlighted

Hi,

Thanks!

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.

0 Kudos
Message 6 of 7
(141 Views)
Highlighted

Hi Rashp8,

 

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

 

Cheers
Brett

Senior Software Development Engineer
Certified LabVIEW Architect and LabVIEW Champion
https://theLonelyAnt.com
0 Kudos
Message 7 of 7
(91 Views)