[Pharo-project] Command Line Interface using FFI
I've spent a few hours playing with Alien+FFI and I did want to have a Command line interface to play and use as a quick browser. Gofer it squeaksource: 'CLInterface'; package: 'ConfigurationOfCLInterface'; load. ConfigurationOfCLInterface load. To play with it write a script, for example startCLI.st, with the following: *CLInterface start* And then, from the command line CogVM -vm-display-null <image> startCLI.st What it does support? - executes smalltalk expressions - handles the errors and shows them into the stdout (so it does not explode :P) - stores variables as a workspace Since I used standard C functions (fgets and printf only) this should work on every platform from scratch (having a VM with FFI working, of course)... The problems I've ran so far: - blocking FFI blocks the vm. I've not tried yet to use threads through FFI (and I don't know if it works. Does it?). But It should be great to start a headless seaside server with a command line :/. Ok, it's a very simple thing, but it allows to execute a expression from a remote server via ssh without doing much :). Guille
On 29 January 2012 21:11, Guillermo Polito <guillermopolito@gmail.com> wrote:
I've spent a few hours playing with Alien+FFI and I did want to have a Command line interface to play and use as a quick browser.
This is something I'd like to have as a part of Coral. What's your opinion on the FFI-libc approach compared to OSProcess? I was actually thinking of doing something like that using NativeBoost :)
Gofer it    squeaksource: 'CLInterface';    package: 'ConfigurationOfCLInterface';    load.
ConfigurationOfCLInterface load.
To play with it write a script, for example startCLI.st, with the following:
CLInterface start
And then, from the command line
CogVM -vm-display-null <image> startCLI.st
What it does support? - executes smalltalk expressions - handles the errors and shows them into the stdout (so it does not explode :P) - stores variables as a workspace Since I used standard C functions (fgets and printf only) this should work on every platform from scratch (having a VM with FFI working, of course)...
The problems I've ran so far: - blocking FFI blocks the vm. I've not tried yet to use threads through FFI (and I don't know if it works. Does it?). But It should be great to start a headless seaside server with a command line :/.
Ok, it's a very simple thing, but it allows to execute a expression from a remote server via ssh without doing much :).
Guille
-- Damien Pollet type less, do more [ | ] http://people.untyped.org/damien.pollet
On Tue, Jan 31, 2012 at 4:10 AM, Damien Pollet <damien.pollet@gmail.com>wrote:
On 29 January 2012 21:11, Guillermo Polito <guillermopolito@gmail.com> wrote:
I've spent a few hours playing with Alien+FFI and I did want to have a Command line interface to play and use as a quick browser.
This is something I'd like to have as a part of Coral.
What's your opinion on the FFI-libc approach compared to OSProcess? I was actually thinking of doing something like that using NativeBoost :)
There is a third option which just uses the stdio streams in StandardFileStream. this has been working in the Cog VMs for some time now.
Gofer it squeaksource: 'CLInterface'; package: 'ConfigurationOfCLInterface'; load.
ConfigurationOfCLInterface load.
To play with it write a script, for example startCLI.st, with the following:
CLInterface start
And then, from the command line
CogVM -vm-display-null <image> startCLI.st
What it does support? - executes smalltalk expressions - handles the errors and shows them into the stdout (so it does not explode :P) - stores variables as a workspace Since I used standard C functions (fgets and printf only) this should work on every platform from scratch (having a VM with FFI working, of course)...
The problems I've ran so far: - blocking FFI blocks the vm. I've not tried yet to use threads through FFI (and I don't know if it works. Does it?). But It should be great to start a headless seaside server with a command line :/.
Ok, it's a very simple thing, but it allows to execute a expression from a remote server via ssh without doing much :).
Guille
-- Damien Pollet type less, do more [ | ] http://people.untyped.org/damien.pollet
-- best, Eliot
I cant get the stdin on FileStream to work. Just blocks irrespective of what I do in sending characters with enter.. or any other trials .. will check a little more On Wed, Feb 1, 2012 at 5:06 AM, Eliot Miranda <eliot.miranda@gmail.com>wrote:
On Tue, Jan 31, 2012 at 4:10 AM, Damien Pollet <damien.pollet@gmail.com>wrote:
On 29 January 2012 21:11, Guillermo Polito <guillermopolito@gmail.com> wrote:
I've spent a few hours playing with Alien+FFI and I did want to have a Command line interface to play and use as a quick browser.
This is something I'd like to have as a part of Coral.
What's your opinion on the FFI-libc approach compared to OSProcess? I was actually thinking of doing something like that using NativeBoost :)
There is a third option which just uses the stdio streams in StandardFileStream. this has been working in the Cog VMs for some time now.
Gofer it squeaksource: 'CLInterface'; package: 'ConfigurationOfCLInterface'; load.
ConfigurationOfCLInterface load.
To play with it write a script, for example startCLI.st, with the following:
CLInterface start
And then, from the command line
CogVM -vm-display-null <image> startCLI.st
What it does support? - executes smalltalk expressions - handles the errors and shows them into the stdout (so it does not explode :P) - stores variables as a workspace Since I used standard C functions (fgets and printf only) this should work on every platform from scratch (having a VM with FFI working, of course)...
The problems I've ran so far: - blocking FFI blocks the vm. I've not tried yet to use threads through FFI (and I don't know if it works. Does it?). But It should be great to start a headless seaside server with a command line :/.
Ok, it's a very simple thing, but it allows to execute a expression from a remote server via ssh without doing much :).
Guille
-- Damien Pollet type less, do more [ | ] http://people.untyped.org/damien.pollet
-- best, Eliot
On Tue, Jan 31, 2012 at 8:35 PM, S Krish <krishnamachari.sudhakar@gmail.com>wrote:
I cant get the stdin on FileStream to work. Just blocks irrespective of what I do in sending characters with enter.. or any other trials .. will check a little more
I assure you it does work with the right image-level code. Here's an interaction with a 3.8/Qwaq derived image on Mac OS: McStalker.macbuild$ uname -a Darwin McStalker 10.8.0 Darwin Kernel Version 10.8.0: Tue Jun 7 16:32:41 PDT 2011; root:xnu-1504.15.3~1/RELEASE_X86_64 x86_64 i386 McStalker.macbuild$ oscfvm ~/Cog/startreader.image squeak> DateAndTime now! 2012-02-03T13:04:24-08:00 squeak> Smalltalk quit! McStalker.macbuild$ On linux: [eliot@mcqfes ~]$ oscogvm/coglinux/squeak Cog/startreader.image squeak> Smalltalk quit! [eliot@mcqfes ~]$ uname -a Linux mcqfes 2.6.18-128.el5 #1 SMP Wed Jan 21 10:44:23 EST 2009 i686 i686 i386 GNU/Linux [eliot@mcqfes ~]$ oscogvm/coglinux/squeak Cog/startreader.image squeak> DateAndTime now! 2012-02-03T13:05:58-08:00 squeak> Smalltalk quit! [eliot@mcqfes ~]$ And windows: U:\Cog>ver Microsoft Windows XP [Version 5.1.2600] U:\Cog>oscogvm\cygwinbuild\build\vm\CroquetConsole.exe startreader.image squeak> DateAndTime now! 2012-02-03T13:07:39-08:00 squeak> Smalltalk quit! U:\Cog> It's crude, using chunk format, but demonstrates the functionality and is very simple. To get this to work requires the attached nextChunkNoTag hack since restoreState:with: seems unreliable (it implements skip: -1, which is used in peek). For Windows you need the 2519 or newer Cog VM.
On Wed, Feb 1, 2012 at 5:06 AM, Eliot Miranda <eliot.miranda@gmail.com>wrote:
On Tue, Jan 31, 2012 at 4:10 AM, Damien Pollet <damien.pollet@gmail.com>wrote:
On 29 January 2012 21:11, Guillermo Polito <guillermopolito@gmail.com> wrote:
I've spent a few hours playing with Alien+FFI and I did want to have a Command line interface to play and use as a quick browser.
This is something I'd like to have as a part of Coral.
What's your opinion on the FFI-libc approach compared to OSProcess? I was actually thinking of doing something like that using NativeBoost :)
There is a third option which just uses the stdio streams in StandardFileStream. this has been working in the Cog VMs for some time now.
Gofer it squeaksource: 'CLInterface'; package: 'ConfigurationOfCLInterface'; load.
ConfigurationOfCLInterface load.
To play with it write a script, for example startCLI.st, with the following:
CLInterface start
And then, from the command line
CogVM -vm-display-null <image> startCLI.st
What it does support? - executes smalltalk expressions - handles the errors and shows them into the stdout (so it does not explode :P) - stores variables as a workspace Since I used standard C functions (fgets and printf only) this should work on every platform from scratch (having a VM with FFI working, of course)...
The problems I've ran so far: - blocking FFI blocks the vm. I've not tried yet to use threads through FFI (and I don't know if it works. Does it?). But It should be great to start a headless seaside server with a command line :/.
Ok, it's a very simple thing, but it allows to execute a expression from a remote server via ssh without doing much :).
Guille
-- Damien Pollet type less, do more [ | ] http://people.untyped.org/damien.pollet
-- best, Eliot
-- best, Eliot
On Fri, Feb 3, 2012 at 1:16 PM, Eliot Miranda <eliot.miranda@gmail.com>wrote:
On Tue, Jan 31, 2012 at 8:35 PM, S Krish < krishnamachari.sudhakar@gmail.com> wrote:
I cant get the stdin on FileStream to work. Just blocks irrespective of what I do in sending characters with enter.. or any other trials .. will check a little more
I assure you it does work with the right image-level code. Here's an interaction with a 3.8/Qwaq derived image on Mac OS:
McStalker.macbuild$ uname -a Darwin McStalker 10.8.0 Darwin Kernel Version 10.8.0: Tue Jun 7 16:32:41 PDT 2011; root:xnu-1504.15.3~1/RELEASE_X86_64 x86_64 i386 McStalker.macbuild$ oscfvm ~/Cog/startreader.image squeak> DateAndTime now! 2012-02-03T13:04:24-08:00 squeak> Smalltalk quit! McStalker.macbuild$
On linux: [eliot@mcqfes ~]$ oscogvm/coglinux/squeak Cog/startreader.image squeak> Smalltalk quit! [eliot@mcqfes ~]$ uname -a Linux mcqfes 2.6.18-128.el5 #1 SMP Wed Jan 21 10:44:23 EST 2009 i686 i686 i386 GNU/Linux [eliot@mcqfes ~]$ oscogvm/coglinux/squeak Cog/startreader.image squeak> DateAndTime now! 2012-02-03T13:05:58-08:00 squeak> Smalltalk quit! [eliot@mcqfes ~]$
And windows: U:\Cog>ver
Microsoft Windows XP [Version 5.1.2600]
U:\Cog>oscogvm\cygwinbuild\build\vm\CroquetConsole.exe startreader.image squeak> DateAndTime now! 2012-02-03T13:07:39-08:00 squeak> Smalltalk quit!
U:\Cog>
It's crude, using chunk format, but demonstrates the functionality and is very simple. To get this to work requires the attached nextChunkNoTag hack since restoreState:with: seems unreliable (it implements skip: -1, which is used in peek). For Windows you need the 2519 or newer Cog VM.
Oops. And to launch it I use this in a workspace: Smalltalk saveAs. [StdioListener new run] newProcess priority: Processor activePriority + 1; resume but Smalltalk saveAs. StdioListener new run should work too, its just that there won't be any UI, because the listener is running in the active UI process. With the threaded VM one can interact with the UI while the listener is blocked. With the non-threaded VM, it is blocked in the read. So to interact with the UI type something like (Delay forSeconds: 1000) wait!
On Wed, Feb 1, 2012 at 5:06 AM, Eliot Miranda <eliot.miranda@gmail.com>wrote:
On Tue, Jan 31, 2012 at 4:10 AM, Damien Pollet <damien.pollet@gmail.com>wrote:
On 29 January 2012 21:11, Guillermo Polito <guillermopolito@gmail.com> wrote:
I've spent a few hours playing with Alien+FFI and I did want to have a Command line interface to play and use as a quick browser.
This is something I'd like to have as a part of Coral.
What's your opinion on the FFI-libc approach compared to OSProcess? I was actually thinking of doing something like that using NativeBoost :)
There is a third option which just uses the stdio streams in StandardFileStream. this has been working in the Cog VMs for some time now.
Gofer it squeaksource: 'CLInterface'; package: 'ConfigurationOfCLInterface'; load.
ConfigurationOfCLInterface load.
To play with it write a script, for example startCLI.st, with the following:
CLInterface start
And then, from the command line
CogVM -vm-display-null <image> startCLI.st
What it does support? - executes smalltalk expressions - handles the errors and shows them into the stdout (so it does not explode :P) - stores variables as a workspace Since I used standard C functions (fgets and printf only) this should work on every platform from scratch (having a VM with FFI working, of course)...
The problems I've ran so far: - blocking FFI blocks the vm. I've not tried yet to use threads through FFI (and I don't know if it works. Does it?). But It should be great to start a headless seaside server with a command line :/.
Ok, it's a very simple thing, but it allows to execute a expression from a remote server via ssh without doing much :).
Guille
-- Damien Pollet type less, do more [ | ] http://people.untyped.org/damien.pollet
-- best, Eliot
-- best, Eliot
-- best, Eliot
participants (4)
-
Damien Pollet -
Eliot Miranda -
Guillermo Polito -
S Krish