ni.com is currently undergoing scheduled maintenance.

Some services may be unavailable at this time. Please contact us for help or try again later.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Python Script in LabVIEW Context

Solved!
Go to solution

Hi , 

 

I've a python script which writes a file periodically (every 2 seconds) . When I run this python script from command prompt or using IDLE, the file is updated periodically and I can read the file. 

 

But when I run the same python script using  system exec VI in LabVIEW context. It doesn't update the file periodically and updates the file when it got terminated. So because of this I can't plot my data in run-time. 

 

Let me know if there is any other way of doing this.

 

 

 

 

 

0 Kudos
Message 1 of 4
(3,017 Views)

Set 'Wait Until Completion' input to False.

An alternative would be to create a BAT file of your command, then call the BAT file using system exec.vi

0 Kudos
Message 2 of 4
(3,004 Views)

Can you share either 

A) the Python script you're using or 

B) a similar script that uses the same method to write to file periodically (and so exhibits the same problem)?


GCentral
0 Kudos
Message 3 of 4
(2,948 Views)
Solution
Accepted by topic author lvbms

Problem solved as I was not using "f.flush()" and "os.fsync(f.fileno())". After adding this I was able to resolve the issue I was facing. It was not a issue with System Exec. Now I can read the file and plot the data as I need. Thanks for pointing out "Wait untill Completion". I need to set it to false because I want to let the script run and don't want to wait for its completion.

 

def write_csv(*args):
my_str= str(args[1]) + "," + ",".join(args[2]) + "\n"
#print (my_str)
file_handle = args[0]
file_handle.write(my_str)
file_handle.flush()
os.fsync(file_handle.fileno())

0 Kudos
Message 4 of 4
(2,917 Views)