LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

System.IO.Stream.Read Hanging

I'm lanuching an FFMPEG instance using the .net Process constructor. I'm enbablng redirecting the Standard Output and Standard Error so that I can read the streams directly in to LabVIEW.

 

The first Stream.Read is requesting 3000 bytes, the actual output is about 2752. However somtimes this invoke node just doesn't return and the program hangs. If I then manualy kill ffmpeg.exe using the task magaer the program continues and it returns the expected number of bytes.

 

According to the MSDN, this menthod should never do this. Does anyone have any ideas?

 

 

0 Kudos
Message 1 of 5
(4,147 Views)

So I've found out a bit more.

Doing anything with the Stream (copying, reading) will hang unless the VI is in highlight execution mode and then it works fine.

 

Install the package.

Create new VI

Go to BD, right click, Test->System Processes->Example->FFMPEG to Frames

Change to your local copy of FFMPEG and a small video.

The file "Process Stream Read2.vi" is the one that needs to have highlight execution on to make it work correctly.

0 Kudos
Message 2 of 5
(4,099 Views)

https://goo.gl/photos/34qZweDU7BCUnMwz8

 

Here's a video of the problem.

 

Regards, Richard

0 Kudos
Message 3 of 5
(4,074 Views)

Hello,

 

Thank you for the detailed information as to your issue. From what I can ascertain of the usage of Stream.Read with standard output, several other users of this functionality have found it to hang in other languages also. Essentially I was able to find two instances where it might hang when calling this function:

 

1. When no data has been input to the stream.

2. When the process with which the standard output/error has been redirected.

 

The solution for most users in this case is to call the Peek() function prior to the Read, if it is indeed greater than zero (buffer is not empty and stream is still alive) then, perform the read, otherwise you could have a polling method whereby it waits for the stream to have data or exits if it is minus 1. Please see links below to other sources which found this issue:

 

1. http://stackoverflow.com/questions/7160187/standardoutput-readtoend-hangs

2. https://social.msdn.microsoft.com/Forums/vstudio/en-US/057f1444-1dea-4c2f-bb48-612478de0f5c/processs...

 

Please see attached modified VI with a possible solution based on what I have found thus far and described above.

 

Best regards,

 

Sarah

0 Kudos
Message 4 of 5
(4,064 Views)

Thank you for your reply.

 

Unfortunatly, I'm not able to open that example as I've not got 2016, I'll have a look at it when I'm home.

 

I've modified my main package to do a peek from the streamreader before attempting the read and even with waiting until the peek returns a non-zero value I still have the same problem. I don't think it can be a timing problem becuase I can wait for 5s before attempting to read the StdErr (so I know there's data there) and this doesn't fix it.

 

I will keep this post updated with any information I find (NI in the US are also looking at it now), however if other languages are also displaying this problem I don't hold out much hope.

 

I still find it strange with how it works with highlight execution on though.

0 Kudos
Message 5 of 5
(4,054 Views)