Hello,
OSProcess thisOSProcess stdOut nextPutAll: 'This is a test'. will print "This is a test" in the shell that started squeak. OSProcess thisOSProcess stdOut close. successfully closes stdOut.
Under linux, if I open a new file after closing stdout it will have the FD #1 (given stdin is not closed too) and I would successfully have redirected stdOut to that file. But in squeak if I do something like:
fd := FileStream fileNamed: 'aGenericPipeline'. fd readWrite. OSProcess thisOSProcess setStdOut. OSProcess thisOSProcess stdOut nextPutAll: 'This is a test',Character lf asString.
Things get weird... (to the point that squeak VM crashes).
I also tried to do:
mkfifo fifo squeak > fifo
But squeak just won't start...
Any suggestions on how reopen stdOut to a desired point other than the default?
On Mon, May 18, 2009 at 11:35:56AM -0300, Casimiro de Almeida Barreto wrote:
Any suggestions on how reopen stdOut to a desired point other than the default?
Hi Casimiro,
I was looking into this just last night, and have gotten far enough so that the following works, and I can verify that the Unix file descriptors are properly duplicated for child processes to inherit correctly.
OSProcess command: 'mkfifo myPipe'. fd := FileStream fileNamed: 'myPipe'. OSProcess thisOSProcess redirectStdOutTo: fd. OSProcess thisOSProcess redirectStdErrTo: fd. OSProcess thisOSProcess stdOut nextPutAll: 'hello '; flush. OSProcess thisOSProcess stdErr nextPutAll: 'world!'; flush. fd next: 11 ==> 'hello world'
This requires some updates to OSProcessPlugin (a primitive for the dup2() system call) and to OSProcess. I'm not done yet, but I'll try to get this cleaned up and posted by this weekend.
Dave
This requires some updates to OSProcessPlugin (a primitive for the dup2() system call) and to OSProcess. I'm not done yet, but I'll try to get this cleaned up and posted by this weekend.
you don't really need a plugin if you have FFI:
dup: srcfd <cdecl: long 'dup' (long) module: 'libc'> ^ self externalCallFailed
dup: srcfd to: dstfd <cdecl: long 'dup2' (long long) module: 'libc'> ^ self externalCallFailed
richie
squeak-dev@lists.squeakfoundation.org