• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: writing to a named pipe (FIFO) fails
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: writing to a named pipe (FIFO) fails


  • Subject: Re: writing to a named pipe (FIFO) fails
  • From: Malcolm Fitzgerald <email@hidden>
  • Date: Wed, 22 Nov 2006 09:44:29 +1100


On 22/11/2006, at 12:32 AM, Cameron Hayne wrote:

I am trying (but failing) to write to a FIFO or named pipe (http://en.wikipedia.org/wiki/Named_pipe) from AppleScript.

from your description it looks like you are succeeding.


Here's an example script (the named pipe at "/Users/myusername/mystuff/myfifo" is set up previously in a Terminal window):
----------------------------------------------------------------------- -----
set fifo to "/Users/myusername/mystuff/myfifo"
do shell script "echo AAA > " & fifo

This works, but it's the end of the shell. Your named pipe is now a file on disk like any other.



set macFifo to POSIX file fifo

try
	write "BBB" to macFifo
on error errString number errNum
	display alert errString & " (" & errNum & ")"
end try


Works (I'm running 10.3.9)


try
	set fd to open for access macFifo with write permission
	write "CCC" to fd
	close access fd
on error errString number errNum
	display alert errString & " (" & errNum & ")"
end try

Works


----------------------------------------------------------------------- -----
The 'do shell script' works fine and the "AAA" gets transmitted to the named pipe.


When you read myfifo at that point does it contain "AAA" ? If so, you succeeded.


But the two attempts ("BBB" & "CCC") to write to the named pipe using 'write' both fail with error -36 which is "ioErr (-36): I/O error (bummers)".
Note that if I change the above example to refer to a regular file, it all works fine.

The way I understand it, it is a regular file. The fact that you named a pipe to generate it doesn't make it different. Am I wrong?



Is there any way to write to a named pipe (FIFO) using 'write' in AppleScript?

All you are doing with a named pipe is dumping the output of a process into a file.


This is an applescript way of doing the same thing.

on timeStamp()
	return (current date) as string
end timeStamp

set fPath to ("" & (path to desktop))
set fname to "ascr.log"
set namedPipe to open for access file (fPath & fname) with write permission


repeat 10 times
	write timeStamp() & return to namedPipe
end repeat

close access namedPipe
# now the results are in the file instead of the ether :-)
read file (fPath & fname)


I want to avoid the use of 'do shell script' for reasons of performance (each 'do shell script' seems to take about 0.1 second and in my AppleScript I will be doing thousands of writes to the named pipe).

In that case, tell us what you are trying to achieve.


malcolm

_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/mailman//archives/applescript-users

This email sent to email@hidden
  • Follow-Ups:
    • Re: writing to a named pipe (FIFO) fails
      • From: Cameron Hayne <email@hidden>
References: 
 >writing to a named pipe (FIFO) fails (From: Cameron Hayne <email@hidden>)

  • Prev by Date: Re: writing to a named pipe (FIFO) fails
  • Next by Date: Re: writing to a named pipe (FIFO) fails
  • Previous by thread: Re: writing to a named pipe (FIFO) fails
  • Next by thread: Re: writing to a named pipe (FIFO) fails
  • Index(es):
    • Date
    • Thread