LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Does System command pipe VI bufferizes data?

Hi,

I have some questions about Pipe VIs on Linux:

1)In my project I open a system command pipe vi that opens another program's shell. Then, using the write file descriptor, I write a series of commands in a loop. I could observe that only when I close the pipe those commands are really sent to the shell, OR when, aparently, something like a  "pipe vi buffer" overflows.

2) In the same situation, I would like to use both the write and read file descriptors. The write pipe vi sends a command to the program's shell and them the read pipe vi reads the shell's results. I tried of many ways, including forcing serialization (open, then write, then read), but it didn't work at all. I could see that the write worked but the read can't read the results.
The most interesting is if I use a ls -l in the open system vi, I can read the directory contents on the read vi...

What's wrong? Is that a problem of LV or Linux? Or of the another program's shell?
What can I do to make sure that a command is issued as it is writen to the pipe?

Thanks in advance for the attention,
0 Kudos
Message 1 of 12
(3,787 Views)
Hi, ratem.

I'll address your questions in order:

1. Can you please attach a screenshot of the segment of your code that's behaving this way? I'd like to see if I can reproduce that behavior on my machine.

2. You say that you can't read the results -- do you mean that no data appears, or that it comes through garbled in some way? If no data is appearing, it's probably because you haven't specified the number of bytes to read in the Read VI. (That input specifies the maximum bytes to read, so you don't have to worry about knowing the precise amount of data you'll receive.)

Let me know if you're still having problems! Have a nice afternoon.
Sarah K.
Search PME
National Instruments
0 Kudos
Message 2 of 12
(3,771 Views)
Hi,
thanks for your attention, but it doesn`t work at all.
As I told before, in the second case, if I use a simple ls -l for example, everything is ok. But when I use psql (PostGreSQL shell utility) it doesn`t work. I am sending a simple VI showing this.

In the first case, I open psql with a system command pipe vi and then use a write pipe afterwards. It writes in the pipe, but seems to flush only when I close the pipe.
I really don`t know if I didn`t understand pipes very well or if it`s a vi misuse or a psql problem or even a vi bug.
Keep in touch,

0 Kudos
Message 3 of 12
(3,767 Views)
Hi, ratem.

Does the delay (in your first question) also occur with a call to ls -l?

In the second question, you say that psql doesn't work. But in what way does it not work? Do you just receive no data? Also, is psql the only command that fails, or are there others as well? I'm particularly interested to see if the failure occurs with other programs that have more than a few arguments. (I see in your code that your call has more than five.)

Let me know. Have a nice evening.
Sarah K.
Search PME
National Instruments
0 Kudos
Message 4 of 12
(3,757 Views)
Hi Sarah.

>Does the delay (in your first question) also occur with a call to ls -l?

No, apparently with system commands there is no problem in reading.

>In the second question, you say that psql doesn't work. But in what way does it not work? Do you just receive no data?
It seems to enter a wait state while the pipe is open. Or, in my opinion, the data written to the pipe is bufferized, and only when I close the pipe everything is sent to psql, which executes all commands without problem!

>Also, is psql the only command that fails, or are there others as well? I'm particularly interested to see if the failure occurs with other programs that have more than a few arguments. (I >see in your code that your call has more than five.)

I tested with system commands  without  problems.  It realy seems to bufferize everything, waiting for a close...
Thanks for your attention,
0 Kudos
Message 5 of 12
(3,754 Views)
Hi, ratem.

I've just created a little code snippet (below), and I'd like you to tell me what happens when you run similar code on your machine. I run the code, read from the FIFO in a terminal, and I'm able to see the data I wrote before the pipe is closed. Does your behavior differ with this code?


Message Edited by sarahk on 04-09-2006 12:36 PM

Message Edited by sarahk on 04-09-2006 12:36 PM

Sarah K.
Search PME
National Instruments
0 Kudos
Message 6 of 12
(3,734 Views)
Hi Sara, thanks for your interest.
I've run the code on my machine, as root and as a normal user. When I "cat" the pipe seems to be empty. Actually, even after closing there were no data in it.
What is happening? Am I doing something stupid on Linux????
ps.: An important detail: the ls -l I told it was working was using the Open System Command Pipe VI then Read Pipe VI, not the Open Pipe VI .


0 Kudos
Message 7 of 12
(3,719 Views)
Ratem,

I may be missing something but I'm not sure why you are using the system command pipe vi.  If all you are doing is trying to run a command and read the output you can use the System Exec.vi.  The attached example should be equivalent to your testapipe2.vi example.

Shawn B.
National Instruments
Use NI products on Linux? Come join the NI Linux Users Community
0 Kudos
Message 8 of 12
(3,704 Views)
Dear Shawn,

I do use the  System Exec.vi in the present, but I didn't want to keep on using it (unless you convice me of the opposite!). You've reached my core problem (?). Since I don't know how system exec vi works I presume that it opens a shell, executes the command, than close the shell, with appropriate outputs. It works fine for me, but one thing: I am using it to store data in PostgreSQL using psql inside a loop that is executed many (tens of thousands) times. Thus I started to think if I could open a pipe and then, inside the loop, use a write pipe vi. I tested this as soon as I got LV8, and it seemed to work fine. But my first test wasn' t though enough...when I put this construction in a real world situation, I could see that only after thousands of inserts (
OR when I forced the pipe to close) that  everything (all commands) were flushed in batch to the database. I really don't know if this is a psql problem, I don't think so, what I really want was to know better the internals of both the system command and the pipe VIs, then I would decide better.

Keep in touch

0 Kudos
Message 9 of 12
(3,699 Views)
Hi, ratem.

I know you said you're using Open System Command Pipe, but I'd just like to verify how you're reading from your fifo.

Using the code from my screenshot above, here's the sequence of events I'm using:

------------------------------------------------------
(from the command prompt)
$ mkfifo sfifo
$ cat < sfifo
[Run the LabVIEW code. "pwd" appears in my command prompt.]
[Now I press Stop in my LabVIEW code and it stops executing without an errors.]
------------------------------------------------------

...which is producing successful results. Is this what you're doing when it fails (and "the pipe seems empty" as you said)?

Thanks.



Sarah K.
Search PME
National Instruments
0 Kudos
Message 10 of 12
(3,690 Views)